是否可以添加带有图像的页眉(带有文本和一张图像)和页脚(带有页码)。我编写了下面的代码来创建一个显示 png 图像的 PDF 文档。
如果可以使用任何其他模块轻松完成此操作,请提出建议。非常感谢示例代码的回复。
use strict;
use PDF::API2::Lite;
use Getopt::Long;
my $outfile;
my $path;
my $options = GetOptions( "outfile=s" => \$outfile,
"images=s" => \$path,);
my @images = sort glob("$path") or die "No Files\n";
my $pdf = PDF::API2::Lite->new();
for my $png ( sort @images ) {
my $image = $pdf->image_png( "$png" );
$pdf->page(1150,450);
$pdf->image($image, 10, 10);
}
$pdf->saveas( $outfile );
最佳答案
在 SO 上等待一天可以节省您 10 分钟阅读模块文档的时间。这并不难,太空。
use PDF::API2 qw();
{
my $pdf = PDF::API2->open('input.pdf');
for my $index (1 .. $pdf->pages) {
my $page = $pdf->openpage($index);
my $txt = $page->text;
$txt->textlabel(300, 700, $pdf->corefont('Helvetica Bold'), 12, 'some Header text');
my $gfx = $page->gfx;
$gfx->image($pdf->image_png('Header_image.png'), 150, 700);
$txt->textlabel(300, 100, $pdf->corefont('Helvetica Bold'), 12, "Page: $index");
}
$pdf->saveas('output.pdf');
$pdf->end;
}
关于perl - 如何使用 PDF::API2::Lite 添加带有图像的页眉、页脚?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2947925/