【发布时间】:2014-02-28 01:03:46
【问题描述】:
我正在使用 Perls PDF::FromHTML 创建 PDF 文件。我的代码如下所示:
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 $!;
由于一开始我很难创建一个实际的 PDF 文件,所以我现在完全按照 cpan 的概要进行操作,即
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');
但是,这会在正确的位置创建一个 PDF 文件,但它只包含一个白页。 HTML 文件是完整的,看起来应该是这样。我错过了什么?
【问题讨论】: