File: 04_headers.pl

package info (click to toggle)
libpdf-api2-simple-perl 1.1.4u-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 172 kB
  • sloc: perl: 823; makefile: 2
file content (64 lines) | stat: -rw-r--r-- 1,213 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/perl

BEGIN { push @INC, '../lib'; }

use PDF::API2::Simple;

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

$pdf->add_font('VerdanaBold');
$pdf->add_font('Verdana');
$pdf->add_page();

for (my $i = 0; $i < 250; $i++) {
    my $text = "$i - All work and no play makes Jack a dull boy";

    $pdf->text( $text, 
		x => $pdf->margin_left,
		autoflow => 'on' );
}

$pdf->save();

sub header {
    my $strokecolor = $pdf->strokecolor;

    $pdf->stroke_color( '#0000FF' );

    $pdf->next_line;
    $pdf->text( 'Unix time of report: ' . time() );

    $pdf->y( $pdf->y - 5 );

    $pdf->line( to_x => $pdf->effective_width,
		to_y => $pdf->y,
		stroke => 'on',
		fill => 'off',
		width => 2 );

    $pdf->y( $pdf->height - 60 );

    $pdf->strokecolor( $strokecolor );
}

sub footer {
    my $fillcolor = $pdf->fill_color;
    my $font = $pdf->current_font;

    $pdf->fill_color( '#552F55' );

    $pdf->set_font( 'VerdanaBold' );
    $pdf->text( 'Page ' . $page_num++,
		x => $pdf->effective_width,
		y => 20,
		align => 'right' );

    $pdf->fill_color( $fillcolor );
    $pdf->current_font( $font );
}