是否可以添加标题(带有文本和一个图像)和页脚(带页码)和图像.我在下面写了代码来创建一个显示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,"Page: $index");
}
$pdf->saveas('output.pdf');
$pdf->end;
}