如何使用PDF :: API2 :: Lite添加带图像的页眉,页脚?

Spa*_*ace 5 pdf perl perl-module

是否可以添加标题(带有文本和一个图像)和页脚(带页码)和图像.我在下面写了代码来创建一个显示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 );
Run Code Online (Sandbox Code Playgroud)

dax*_*xim 5

在 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;
}
Run Code Online (Sandbox Code Playgroud)