File: 012_pages

package info (click to toggle)
libpdf-builder-perl 3.027-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 23,992 kB
  • sloc: perl: 107,532; makefile: 10
file content (47 lines) | stat: -rw-r--r-- 996 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
#!/usr/bin/perl

use strict;
use warnings;

use lib '../lib';
use PDF::Builder;

#my $compress = 'none'; # uncompressed streams
my $compress = 'flate'; # compressed streams

my $pdf = PDF::Builder->new(-compress => $compress);
my $font = $pdf->corefont('Arial-Bold');

# input: empty page. writes current page number on it (total number of pages)
# uses global $pdf to get number of pages
sub mark {
    my ($page, $pageno) = @_;

    my $t = $page->text();

    $t->font($font, 20);
    $t->translate(20, 700);
    if (defined $pageno) {
        $t->text($pageno);  # the given page number 
    } else {
        $t->text($pdf->pages());  # current page number 1, 2, 3,...
    }
    return;
}

# create pages 1 - 8
for (1..8) {
    mark($pdf->page());
}

# create ninth page, inserted before old page 2
mark($pdf->page(2));

# create some Front Matter (TOC, etc.) pages i, ii, iii
mark($pdf->page(1), 'i');
mark($pdf->page(2), 'ii');
mark($pdf->page(3), 'iii');

$pdf->saveas("$0.pdf");

__END__