I'm using PDF::FromHTML to generate a PDF from HTML(as the name of the module would imply) :)
I'm able to run it from the command line fine and receive my expected output - however when I use the exact same code in my web app, the output doesn't look correct at all - text is appearing in the wrong places and not all of it is appearing.
I am using the exact same input file in the web app and on the command line - some reason when it's called from inside my web app, it's appearing differently.
Here is the code:
use PDF::FromHTML;
my $filename = '/tmp/backup.html';
my $font = 'Helvetica';
my $encoding = 'utf-8';
my $size = 12;
my $landscape = 0;
my $pdf = PDF::FromHTML->new(
encoding => $encoding,
);
my $input_file = $filename;
my $output_file = "$input_file.pdf";
warn "$input_file\n$output_file\n";
$pdf->load_file($input_file);
$pdf->convert(
Font => $font,
LineHeight => $size,
Landscape => $landscape,
);
$pdf->write_file($output_file);
The web app code is the same, just with that block thrown into a method.
I have looked at the two generated PDF files in a hex editor and found the differences. They're the same until a block whose intent I can't understand...
Good PDF contents at that block:
/Length 302 >> stream
**binary data
endstream endobj
10 0 obj << /Filter [ /FlateDecode ] /Length 966
Bad PDF contents:
/Length 306 >> stream
**binary data
endstream endobj
10 0 obj << /Filter [ /FlateDecode ] /Length 559
As you can see, the length of the content contained in here differs, as does the binary data contained in that stream(the length 302 vs length 306 one) as well as the next stream(the length 966 vs 559 one).
I'm not entirely sure what could be causing this discrepancy, the only thing I can think of is some sort of difference in the environments when I'm running this as my user on the command line versus running it from the web app. I don't know where I should start with debugging that, however.