使用perl的PDF :: API2 :: SIMPLE - 页眉和页脚

时间:2010-06-30 20:41:16

标签: perl perl-module

如何在第一页上打印页眉和页脚?

1 个答案:

答案 0 :(得分:2)

这是一个粗略但有效的例子:

use strict;
use warnings;
use PDF::API2::Simple;

our $PageNo;

my $pdf = PDF::API2::Simple->new(
    file   => 'file.pdf',
    header => \&header,
    footer => \&footer,
);

$pdf->add_font('Verdana');

for my $page (1..3) {
    $pdf->add_page;
    $pdf->text( 'blah' x 300, autoflow => 'on' );
}
$pdf->save;  


sub header { 
    $PageNo++;
    return if $PageNo == 1;
    shift->text( 'Header text here' );
}

sub footer { 
    return if $PageNo == 1;
    shift->text( 'page:  ' . $PageNo, x => 10, y => 10 );
}