Subject: | Constructor parameter (file name) should not be re-used 'as is' to receive file content |
use strict;
use warnings;
use CAM::PDF;
my $utf8_name = "\x{03C0}.pdf";
system("cp pdf15.pdf $utf8_name");
CAM::PDF-> new( $utf8_name )
or die $CAM::PDF::errstr;
The 'pdf15.pdf' is part of test suite and known to be valid. File content is read into same scalar, which was passed to constructor as filename. If filename happens to be utf8, then content string remains utf8, not byte string (regardless of binmode performed on filehandle). PDF streams are inflated (through Text::PDF) using OO-interface of Compress::Zlib. Which doesn't like utf8 strings:
use strict;
use warnings;
use feature 'say';
use utf8;
use Compress::Zlib;
my $x = my $y = compress( 'foo' );
utf8::upgrade( $x );
utf8::upgrade( $y );
my $i = Compress::Zlib::inflateInit();
say uncompress( $x );
say for $i-> inflate( $y );
"$content = undef;" after line 313 in PDF.pm will fix it.