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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
#!/usr/bin/perl
use strict;
use warnings;
use lib '../lib';
use PDF::Builder;
use PDF::Builder::Util;
#my $compress = 'none'; # uncompressed streams
my $compress = 'flate'; # compressed streams
my $section_length = 32; # examples per old and new methods
my @labels = (
# new method page_labels()
'upper case Roman numeral I',
'upper case Roman numeral II',
'upper case Roman numeral III',
'upper case Roman numeral IV',
'decimal (Arabic) number 1',
'decimal (Arabic) number 2',
'decimal (Arabic) number 3',
'decimal (Arabic) number 4',
'decimal (Arabic) number 5',
'decimal (Arabic) number 6',
'decimal (Arabic) number 7',
'decimal (Arabic) number 8',
'decimal (Arabic) number 9',
'decimal (Arabic) number 10',
'prefixed A-1',
'prefixed A-2',
'prefixed B-1',
'prefixed B-2',
'prefixed C-1',
'prefixed C-2',
'decimal (Arabic) number 11',
'decimal (Arabic) number 12',
'upper case letter A',
'upper case letter B',
'lower case Roman numeral i',
'lower case Roman numeral ii',
'no counter (blank)',
'no counter (blank)',
'prefix, no counter Z',
'prefix, no counter Z',
'prefix, uc Roman Index I',
'prefix, uc Roman Index II',
# old method pageLabel()
'upper case Roman numeral I',
'upper case Roman numeral II',
'upper case Roman numeral III',
'upper case Roman numeral IV',
'decimal (Arabic) number 1',
'decimal (Arabic) number 2',
'decimal (Arabic) number 3',
'decimal (Arabic) number 4',
'decimal (Arabic) number 5',
'decimal (Arabic) number 6',
'decimal (Arabic) number 7',
'decimal (Arabic) number 8',
'decimal (Arabic) number 9',
'decimal (Arabic) number 10',
'prefixed A-1',
'prefixed A-2',
'prefixed B-1',
'prefixed B-2',
'prefixed C-1',
'prefixed C-2',
'decimal (Arabic) number 11',
'decimal (Arabic) number 12',
'upper case letter A',
'upper case letter B',
'lower case Roman numeral i',
'lower case Roman numeral ii',
'no counter (blank)',
'no counter (blank)',
'prefix, no counter Z',
'prefix, no counter Z',
'prefix, uc Roman Index I',
'prefix, uc Roman Index II',
# extra: these two styles (4 pages) combined one call, pageLabel only
'lower case letter c',
'lower case letter d',
'lc Roman and prefixed App-iv',
'lc Roman and prefixed App-v',
);
my $pdf = PDF::Builder->new(-compress => $compress);
my $f1=$pdf->corefont('Helvetica', -encode=>'latin1'); # unused?
my $f2=$pdf->corefont('Helvetica-Bold', -encode=>'latin1'); # "Page Index=" text
# initial pass, create 2 x $section_length-1 pages labeled
# "Page Index=n" for n=0-$section_length
# extra pages for pageLabel combined -1 -> +3
foreach my $i (0 .. 2*$section_length+3) {
my $page = $pdf->page();
$page->mediabox(595,842);
my $text=$page->text();
$text->textlabel(40,700, $f2, 20, 'Page Index='.$i.', Physical Page='.($i+1));
$text->textlabel(40,670, $f2, 20, 'thumbnail label should be '.$labels[$i]);
}
# modify page numbering /Catalog /PageLabels entries
# note that each style change resets page to 1
# this number NOT on printed page... only in reader thumbnail
# and possibly the reader's display page
# ---------- NEW method using page_labels()
# pages 1..4 should be Upper Case Roman (I..IV)
$pdf->page_labels(1, -style => 'Roman' ); # << /S /R >> default St 1
# pages 5..14 s/b decimal, restart at 1 (1..10)
$pdf->page_labels(5, -start => 1 ); # << /S /D /St 1 >>
# pages 15..16 s/b A-decimal, restart at 1 (A-1, A-2)
$pdf->page_labels(15, -start => 1, -prefix => 'A-' ); # << /P (A-) /S /D /St 1 >>
# pages 17..18 s/b B-1, B-2
$pdf->page_labels(17, -start => 1, -prefix => 'B-' ); # << /P (B-) /S /D /St 1 >>
# pages 19..20 s/b C-1, C-2
$pdf->page_labels(19, -start => 1, -prefix => 'C-' ); # << /P (C-) /S /D /St 1 >>
# pages 21..22 s/b decimal, restart at 11 (11..12)
$pdf->page_labels(21, -start => 11 ); # << /S /D /St 11 >>
# pages 23..24 s/b Alpha, auto-restarts at 1 (A, B)
$pdf->page_labels(23, -style => 'Alpha' ); # << /S /A >>
# pages 25..26 s/b lowercase roman, auto-restarts at 1 (i, ii)
$pdf->page_labels(25, -style => 'roman' ); # << /S /r >>
# pages 27..28 s/b blank (nocounter)
$pdf->page_labels(27, -style => 'nocounter' );
# pages 29..30 s/b blank (nocounter) with Z prefix
$pdf->page_labels(29, -style => 'nocounter', -prefix => 'Z' );
# pages 31..32 s/b prefix Index plus UC Roman
$pdf->page_labels(31, style => 'Roman', prefix => 'Index ' );
# ---------- OLD method using pageLabel()
# pages $section_length+0..3 should be Upper Case Roman (I..IV)
$pdf->pageLabel($section_length+0, { -style => 'Roman' }); # << /S /R >> default St 1
# pages $section_length+4..13 s/b decimal, restart at 1 (1..10)
$pdf->pageLabel($section_length+4, { -start => 1 }); # << /S /D /St 1 >>
# pages $section_length+14..15 s/b A-decimal, restart at 1 (A-1, A-2)
$pdf->pageLabel($section_length+14, { -start => 1, -prefix => 'A-' }); # << /P (A-) /S /D /St 1 >>
# pages $section_length+16..17 s/b B-1, B-2
$pdf->pageLabel($section_length+16, { -start => 1, -prefix => 'B-' }); # << /P (B-) /S /D /St 1 >>
# pages $section_length+18..19 s/b C-1, C-2
$pdf->pageLabel($section_length+18, { -start => 1, -prefix => 'C-' }); # << /P (C-) /S /D /St 1 >>
# pages $section_length+20..21 s/b decimal, restart at 11 (10..11)
$pdf->pageLabel($section_length+20, { -start => 11 }); # << /S /D /St 11 >>
# pages $section_length+22..23 s/b Alpha, auto-restarts at 1 (A, B)
$pdf->pageLabel($section_length+22, { -style => 'Alpha' }); # << /S /A >>
# pages $section_length+24..25 s/b lowercase roman, auto-restarts at 1 (i, ii)
$pdf->pageLabel($section_length+24, { -style => 'roman' }); # << /S /r >>
# pages $section_length+26..27 s/b blank (nocounter)
$pdf->pageLabel($section_length+26, { -style => 'nocounter' });
# pages $section_length+28..29 s/b blank (nocounter) with Z prefix
$pdf->pageLabel($section_length+28, { -style => 'nocounter', -prefix => 'Z' });
# pages $section_length+30..31 s/b prefix Index plus UC Roman
$pdf->pageLabel($section_length+30, { 'style' => 'Roman', 'prefix' => 'Index ' });
# -------------
# combine two calls into one for pageLabel only!
$pdf->pageLabel($section_length+32, { style => 'alpha', start => 3 },
$section_length+34, { style => 'roman', start => 4, prefix => 'App-' });
# -------------
$pdf->saveas("$0.pdf");
$pdf->end();
exit;
__END__
|