I'm using Perl
s PDF::FromHTML
to create a PDF-file. My code looks like this:
open HTML, ">", "file.html";
...
close HTML;
chmod(0777, "file.html");
my $pdf = PDF::FromHTML->new(encoding => 'utf-8');
$pdf->load_file("file.html") or die $!;
$pdf->convert(
Font => 'Arial',
LineHeight => 10,
Landscape => 1
);
$pdf->write_file("file.pdf") or die $!;
Since I had difficulties creating an actual PDF-file at the beginning, I'm now exactly following the synopsis on cpan, which is
my $pdf = PDF::FromHTML->new( encoding => 'utf-8' );
# Loading from a file:
$pdf->load_file('source.html');
# Perform the actual conversion:
$pdf->convert(
# With PDF::API2, font names such as 'traditional' also works
Font => 'font.ttf',
LineHeight => 10,
Landscape => 1,
);
# Write to a file:
$pdf->write_file('target.pdf');
However this creates a PDF-file at the right location, but it only consists of a white page. The HTML-file is complete and looks like it should look. What am I missing?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…