line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PDF::Builder::Docs; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1917
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
332
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '3.024'; # VERSION |
7
|
|
|
|
|
|
|
our $LAST_UPDATE = '3.024'; # manually update whenever code is changed |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# originally part of Builder.pm, it was split out due to its length |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
PDF::Builder::Docs - additional documentation for Builder module |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SOME SPECIAL NOTES |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head2 Software Development Kit |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
There are four levels of involvement with PDF::Builder. Depending on what you |
20
|
|
|
|
|
|
|
want to do, different kinds of installs are recommended. |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
B<1.> Simply installing PDF::Builder as a prerequisite for running some other |
23
|
|
|
|
|
|
|
package. All you need to do is install the CPAN package for PDF::Builder, and |
24
|
|
|
|
|
|
|
it will load the .pm files into your Perl library. If the other package prereqs |
25
|
|
|
|
|
|
|
PDF::Builder, its installer may download and install PDF::Builder automatically. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
B<2.> You want to write a Perl program that uses PDF::Builder functions. In |
28
|
|
|
|
|
|
|
addition to installing PDF::Builder from CPAN, you will want documentation on |
29
|
|
|
|
|
|
|
it. Obtain a copy of the product from GitHub |
30
|
|
|
|
|
|
|
(https://github.com/PhilterPaper/Perl-PDF-Builder) or as a gzipped tar file from CPAN. |
31
|
|
|
|
|
|
|
This includes a utility to |
32
|
|
|
|
|
|
|
build (from POD) a library of HTML documents, as well as examples (examples/ |
33
|
|
|
|
|
|
|
directory) and contributed sample programs (contrib/ directory). |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
B<3.> You want to modify PDF::Builder files. In addition to the CPAN and GitHub |
36
|
|
|
|
|
|
|
distributions, you I choose to keep a local Git repository for tracking |
37
|
|
|
|
|
|
|
your changes. Depending on whether or not your PDF::Builder copy is being used |
38
|
|
|
|
|
|
|
for production purposes, you may want to do your editing and testing in the Perl |
39
|
|
|
|
|
|
|
library installation (I) or in a different place. The "t" tests (t/ |
40
|
|
|
|
|
|
|
directory) and examples provide good regression tests to ensure that you haven't |
41
|
|
|
|
|
|
|
broken anything. If you do your editing on the live code, don't forget when done |
42
|
|
|
|
|
|
|
to copy the changes back into the master version you keep! |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
B<4.> You want to contribute to the development of PDF::Builder. You will need a |
45
|
|
|
|
|
|
|
local Git repository (and a GitHub account), so that when you've got it all |
46
|
|
|
|
|
|
|
done, you can issue a "Pull Request" to bring it to our attention. We can't |
47
|
|
|
|
|
|
|
guarantee that your work will be incorporated into the project, but at least we |
48
|
|
|
|
|
|
|
will look at it. From time to time, a new CPAN version will be issued. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
If you want to make substantial changes for public use, and can't come to a |
51
|
|
|
|
|
|
|
meeting of minds with us, you can even start your own GitHub project and |
52
|
|
|
|
|
|
|
register a new CPAN project (that's what we did, I PDF::API2). Please |
53
|
|
|
|
|
|
|
don't just assume that we don't want your changes -- at least propose what you |
54
|
|
|
|
|
|
|
want to do in writing, so we can consider it. We're always looking for people to |
55
|
|
|
|
|
|
|
help out and expand PDF::Builder. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head2 Optional Libraries |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
PDF::Builder can make use of some optional libraries, which are not I |
60
|
|
|
|
|
|
|
for a successful installation. If you want improved speed and capabilities for |
61
|
|
|
|
|
|
|
certain functions, you may want to install and use these libraries: |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
B<*> Graphics::TIFF -- PDF::Builder inherited a rather slow, buggy, and limited |
64
|
|
|
|
|
|
|
TIFF image library from PDF::API2. If Graphics::TIFF (available on CPAN, uses |
65
|
|
|
|
|
|
|
libtiff.a) is installed, PDF::Builder will use that instead, unless you specify |
66
|
|
|
|
|
|
|
that it is to use the old, pure Perl library. The only time you might want to |
67
|
|
|
|
|
|
|
consider this is when you need to pass an open filehandle to C |
68
|
|
|
|
|
|
|
instead of a file name. See resolved bug reports RT 84665 and RT 118047, as well |
69
|
|
|
|
|
|
|
as C, for more information. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
B<*> Image::PNG::Libpng -- PDF::Builder inherited a rather slow and buggy pure |
72
|
|
|
|
|
|
|
Perl PNG image library from PDF::API2. If Image::PNG::Libpng (available on |
73
|
|
|
|
|
|
|
CPAN, uses libpng.a) is installed, PDF::Builder will use that instead, unless |
74
|
|
|
|
|
|
|
you specify that it is to use the old, pure Perl library. Using the new library |
75
|
|
|
|
|
|
|
will give you improved speed, the ability to use 16 bit samples, and the |
76
|
|
|
|
|
|
|
ability to read interlaced PNG files. See resolved bug report RT 124349, as well |
77
|
|
|
|
|
|
|
as C, for more information. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
B<*> HarfBuzz::Shaper -- This library enables PDF::Builder to handle complex |
80
|
|
|
|
|
|
|
scripts (Arabic, Devanagari, etc.) as well as non-LTR writing systems. It is |
81
|
|
|
|
|
|
|
also useful for Latin and other simple scripts, for ligatures and improved |
82
|
|
|
|
|
|
|
kerning. HarfBuzz::Shaper is based on a set of HarfBuzz libraries, which it |
83
|
|
|
|
|
|
|
will attempt to build if they are not found. See C for more |
84
|
|
|
|
|
|
|
information. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Note that the installation process B attempt to install these |
87
|
|
|
|
|
|
|
libraries automatically. If you don't wish to use one or more of them, you are |
88
|
|
|
|
|
|
|
free to uninstall the optional librarie(s). If one or more failed to install, |
89
|
|
|
|
|
|
|
no need to panic -- you simply won't be able to use some advanced features, |
90
|
|
|
|
|
|
|
unless you are able to manually install the modules (e.g., with "cpan install"). |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 Strings (Character Text) |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Perl, and hence PDF::Builder, use strings that support the full range of |
95
|
|
|
|
|
|
|
Unicode characters. When importing strings into a Perl program, for example |
96
|
|
|
|
|
|
|
by reading text from a file, you must be aware of what their character encoding |
97
|
|
|
|
|
|
|
is. Single-byte encodings (default is 'latin1'), represented as bytes of value |
98
|
|
|
|
|
|
|
0x00 through 0xFF (0..255), will produce different results if you do something |
99
|
|
|
|
|
|
|
that depends on the encoding, such as sorting, searching, or comparing any |
100
|
|
|
|
|
|
|
two non-ASCII characters. This also applies to any characters (text) hard |
101
|
|
|
|
|
|
|
coded into the Perl program. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
You can always decode the text from external encoding (ASCII, UTF-8, Latin-3, |
104
|
|
|
|
|
|
|
etc.) into the Perl (internal) UTF-8 multibyte encoding. This uses one to four |
105
|
|
|
|
|
|
|
bytes to represent each character. See pragma C and module C for |
106
|
|
|
|
|
|
|
details about decoding text. Note that only TrueType fonts (C) can |
107
|
|
|
|
|
|
|
make direct use of UTF-8-encoded text. Other font types (core, T1, etc.) can |
108
|
|
|
|
|
|
|
only use single-byte encoded text. If your text is ASCII, Latin-1, or CP-1252, |
109
|
|
|
|
|
|
|
you I just leave the Perl strings as the default single-byte encoding. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Then, there is the matter of encoding the I |
112
|
|
|
|
|
|
|
font character sets. You're not actually I the text on output, but |
113
|
|
|
|
|
|
|
are telling the output system (and Reader) what encoding the output byte stream |
114
|
|
|
|
|
|
|
represents, and what character glyphs they should generate. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
If you confine your text to plain ASCII (0x00 .. 0x7F byte values) or even |
117
|
|
|
|
|
|
|
Latin-1 or CP-1252 (0x00 .. 0xFF byte values), you can |
118
|
|
|
|
|
|
|
use default (non-UTF-8) Perl strings and use the default output encoding |
119
|
|
|
|
|
|
|
(WinAnsiEncoding), which is more-or-less Windows CP-1252 (a superset |
120
|
|
|
|
|
|
|
in turn, of ISO-8859-1 Latin-1). If your text uses any other characters, you |
121
|
|
|
|
|
|
|
will need to be aware of what encoding your text strings are (in the Perl string |
122
|
|
|
|
|
|
|
and for declaring output glyph generation). |
123
|
|
|
|
|
|
|
See L, L and L in L |
124
|
|
|
|
|
|
|
for additional information. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head3 Some Internal Details |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Some of the following may be a bit scary or confusing to beginners, so don't |
129
|
|
|
|
|
|
|
be afraid to skip over it until you're ready for it... |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Perl (and PDF::Builder) internally use strings which are either single-byte |
132
|
|
|
|
|
|
|
(ISO-8859-1/Latin-1) or multibyte UTF-8 encoded (there is an internal flag |
133
|
|
|
|
|
|
|
marking the string as UTF-8 or not). |
134
|
|
|
|
|
|
|
If you work I in ASCII or Latin-1 or CP-1252 (each a superset of the |
135
|
|
|
|
|
|
|
previous), you should be OK in not doing anything special about your string |
136
|
|
|
|
|
|
|
encoding. You can just use the default Perl single byte strings (internally |
137
|
|
|
|
|
|
|
marked as I UTF-8) and the default output encoding (WinAnsiEncoding). |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
If you intend to use input from a variety of sources, you should consider |
140
|
|
|
|
|
|
|
decoding (converting) your text to UTF-8, which will provide an internally |
141
|
|
|
|
|
|
|
consistent representation (and your Perl code itself should be saved in UTF-8, |
142
|
|
|
|
|
|
|
in case you want to use any hard coded non-ASCII characters). In any string, |
143
|
|
|
|
|
|
|
non-ASCII characters (0x80 or higher) would be converted to the Perl UTF-8 |
144
|
|
|
|
|
|
|
internal representation, via C<$string = Encode::decode(MY_ENCODING, $input);>. |
145
|
|
|
|
|
|
|
C would be a string like 'latin1', 'cp-1252', 'utf8', etc. Similar |
146
|
|
|
|
|
|
|
capabilities are available for declaring a I to be in a certain encoding. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Be aware that if you use UTF-8 encoding for your text, that only TrueType font |
149
|
|
|
|
|
|
|
output (C) can handle it directly. Corefont and Type1 output will |
150
|
|
|
|
|
|
|
require that the text will have to be converted back into a single-byte encoding |
151
|
|
|
|
|
|
|
(using C), which may need to be declared with C (for |
152
|
|
|
|
|
|
|
C or C). If you have any characters I found in the |
153
|
|
|
|
|
|
|
selected single-byte I (but I found in the font itself), you |
154
|
|
|
|
|
|
|
will need to use C to break up the font glyphs into 256 character |
155
|
|
|
|
|
|
|
planes, map such characters to 0x00 .. 0xFF in the appropriate plane, and |
156
|
|
|
|
|
|
|
switch between font planes as necessary. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Core and Type1 fonts (output) use the byte values in the string (single-byte |
159
|
|
|
|
|
|
|
encoding only!) and provide a byte-to-glyph mapping record for each plane. |
160
|
|
|
|
|
|
|
TrueType outputs a group of four hexadecimal digits representing the "CId" |
161
|
|
|
|
|
|
|
(character ID) of each character. The CId does not correspond to either the |
162
|
|
|
|
|
|
|
single-byte or UTF-8 internal representations of the characters. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
The bottom line is that you need to know what the internal representation of |
165
|
|
|
|
|
|
|
your text is, so that the output routines can tell the PDF reader about it |
166
|
|
|
|
|
|
|
(via the PDF file). The text will not be translated upon output, but the PDF |
167
|
|
|
|
|
|
|
reader needs to know what the encoding in use is, so it knows what glyph to |
168
|
|
|
|
|
|
|
associate with each byte (or byte sequence). |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Note that some operating systems and Perl flavors are reputed to be strict |
171
|
|
|
|
|
|
|
about encoding names. For example, B (an alias) may be rejected as |
172
|
|
|
|
|
|
|
invalid, while B (a canonical value) will work. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
By the way, it is recommended that you be using I Perl 5.10 if you |
175
|
|
|
|
|
|
|
are going to be using any non-ASCII characters. Perl 5.8 may be a little |
176
|
|
|
|
|
|
|
unpredictable in handling such text. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head2 Rendering Order |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
For better or worse, for compatibility purposes, PDF::Builder continues the |
181
|
|
|
|
|
|
|
same rendering model as used by PDF::API2 (and possibly its predecessors). That |
182
|
|
|
|
|
|
|
is, all graphics I are put into one record, and all |
183
|
|
|
|
|
|
|
text output I goes into another |
184
|
|
|
|
|
|
|
record. Which one is output first, is whichever is declared first. This can |
185
|
|
|
|
|
|
|
lead to unexpected results, where items are rendered in (apparently) the |
186
|
|
|
|
|
|
|
wrong order. That is, text and graphics items are not necessarily output |
187
|
|
|
|
|
|
|
(rendered) in the same order as they were created in code. Two items in the |
188
|
|
|
|
|
|
|
same object (e.g., C<$text>) I be rendered in the same order as they were |
189
|
|
|
|
|
|
|
coded, but items from different objects may not be rendered in the expected |
190
|
|
|
|
|
|
|
order. The following example (source code and annotated PDF excerpts) will |
191
|
|
|
|
|
|
|
hopefully illustrate the issue: |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
use strict; |
194
|
|
|
|
|
|
|
use warnings; |
195
|
|
|
|
|
|
|
use PDF::Builder; |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
# demonstrate text and graphics object order |
198
|
|
|
|
|
|
|
# |
199
|
|
|
|
|
|
|
my $fname = "objorder"; |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
my $paper_size = "Letter"; |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
# see the text and graphics stream contents |
204
|
|
|
|
|
|
|
my $pdf = PDF::Builder->new(compress => 'none'); |
205
|
|
|
|
|
|
|
$pdf->mediabox($paper_size); |
206
|
|
|
|
|
|
|
my $page = $pdf->page(); |
207
|
|
|
|
|
|
|
# adjust path for your operating system |
208
|
|
|
|
|
|
|
my $fontTR = $pdf->ttfont('C:\\Windows\\Fonts\\timesbd.ttf'); |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
For the first group, you might expect the "under" line to be output, then the |
211
|
|
|
|
|
|
|
filled circle (disc) partly covering it, then the "over" line covering the |
212
|
|
|
|
|
|
|
disc, and finally a filled rectangle (bar) over both lines. What actually |
213
|
|
|
|
|
|
|
happened is that the C<$grfx> graphics object was declared first, so everything |
214
|
|
|
|
|
|
|
in that object (the disc and bar) is output first, and the text object C<$text> |
215
|
|
|
|
|
|
|
(both lines) comes afterwards. The result is that the text lines are on I |
216
|
|
|
|
|
|
|
of the graphics drawings. |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
# ---------------------------- |
219
|
|
|
|
|
|
|
# 1. text, orange ball over, text over, bar over |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
my $grfx1 = $page->gfx(); |
222
|
|
|
|
|
|
|
my $text1 = $page->text(); |
223
|
|
|
|
|
|
|
$text1->font($fontTR, 20); # 20 pt Times Roman bold |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
$text1->fillcolor('black'); |
226
|
|
|
|
|
|
|
$grfx1->strokecolor('blue'); |
227
|
|
|
|
|
|
|
$grfx1->fillcolor('orange'); |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
$text1->translate(50,700); |
230
|
|
|
|
|
|
|
$text1->text_left("This text should be under everything."); |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
$grfx1->circle(100,690, 30); |
233
|
|
|
|
|
|
|
$grfx1->fillstroke(); |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
$text1->translate(50,670); |
236
|
|
|
|
|
|
|
$text1->text_left("This text should be over the ball and under the bar."); |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
$grfx1->rect(160,660, 20,70); |
239
|
|
|
|
|
|
|
$grfx1->fillstroke(); |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
% ---------------- group 1: define graphics object first, then text |
242
|
|
|
|
|
|
|
11 0 obj << /Length 690 >> stream % obj 11 is graphics for (1) |
243
|
|
|
|
|
|
|
0 0 1 RG % stroke blue |
244
|
|
|
|
|
|
|
1 0.647059 0 rg % fill orange |
245
|
|
|
|
|
|
|
130 690 m ... c h B % draw and fill circle |
246
|
|
|
|
|
|
|
160 660 20 70 re B % draw and fill bar |
247
|
|
|
|
|
|
|
endstream endobj |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
12 0 obj << /Length 438 >> stream % obj 12 is text for (1) |
250
|
|
|
|
|
|
|
BT |
251
|
|
|
|
|
|
|
/TiCBA 20 Tf % Times Roman Bold 20pt |
252
|
|
|
|
|
|
|
0 0 0 rg % fill black |
253
|
|
|
|
|
|
|
1 0 0 1 50 700 Tm % position text |
254
|
|
|
|
|
|
|
<0037 ... 0011> Tj % "under" line |
255
|
|
|
|
|
|
|
1 0 0 1 50 670 Tm % position text |
256
|
|
|
|
|
|
|
<0037 ... 0011> Tj % "over" line |
257
|
|
|
|
|
|
|
ET |
258
|
|
|
|
|
|
|
endstream endobj |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
The second group is the same as the first, with the only difference being |
261
|
|
|
|
|
|
|
that the text object was declared first, and then the graphics object. The |
262
|
|
|
|
|
|
|
result is that the two text lines are rendered first, and then the disc and |
263
|
|
|
|
|
|
|
bar are drawn I them. |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
# ---------------------------- |
266
|
|
|
|
|
|
|
# 2. (1) again, with graphics and text order reversed |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
my $text2 = $page->text(); |
269
|
|
|
|
|
|
|
my $grfx2 = $page->gfx(); |
270
|
|
|
|
|
|
|
$text2->font($fontTR, 20); # 20 pt Times Roman bold |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
$text2->fillcolor('black'); |
273
|
|
|
|
|
|
|
$grfx2->strokecolor('blue'); |
274
|
|
|
|
|
|
|
$grfx2->fillcolor('orange'); |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
$text2->translate(50,600); |
277
|
|
|
|
|
|
|
$text2->text_left("This text should be under everything."); |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
$grfx2->circle(100,590, 30); |
280
|
|
|
|
|
|
|
$grfx2->fillstroke(); |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
$text2->translate(50,570); |
283
|
|
|
|
|
|
|
$text2->text_left("This text should be over the ball and under the bar."); |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
$grfx2->rect(160,560, 20,70); |
286
|
|
|
|
|
|
|
$grfx2->fillstroke(); |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
% ---------------- group 2: define text object first, then graphics |
289
|
|
|
|
|
|
|
13 0 obj << /Length 438 >> stream % obj 13 is text for (2) |
290
|
|
|
|
|
|
|
BT |
291
|
|
|
|
|
|
|
/TiCBA 20 Tf % Times Roman Bold 20pt |
292
|
|
|
|
|
|
|
0 0 0 rg % fill black |
293
|
|
|
|
|
|
|
1 0 0 1 50 600 Tm % position text |
294
|
|
|
|
|
|
|
<0037 ... 0011> Tj % "under" line |
295
|
|
|
|
|
|
|
1 0 0 1 50 570 Tm % position text |
296
|
|
|
|
|
|
|
<0037 ... 0011> Tj % "over" line |
297
|
|
|
|
|
|
|
ET |
298
|
|
|
|
|
|
|
endstream endobj |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
14 0 obj << /Length 690 >> stream % obj 14 is graphics for (2) |
301
|
|
|
|
|
|
|
0 0 1 RG % stroke blue |
302
|
|
|
|
|
|
|
1 0.647059 0 rg % fill orange |
303
|
|
|
|
|
|
|
130 590 m ... h B % draw and fill circle |
304
|
|
|
|
|
|
|
160 560 20 70 re B % draw and fill bar |
305
|
|
|
|
|
|
|
endstream endobj |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
The third group defines two text and two graphics objects, in the order that |
308
|
|
|
|
|
|
|
they are expected in. The "under" text line is output first, then the orange |
309
|
|
|
|
|
|
|
disc graphics is output, partly covering the text. The "over" text line is now |
310
|
|
|
|
|
|
|
output -- it's actually I the disc, but is orange because the previous |
311
|
|
|
|
|
|
|
object stream (first graphics object) left the fill color (also used for text) |
312
|
|
|
|
|
|
|
as orange, because we didn't explicitly set the fill color before outputting |
313
|
|
|
|
|
|
|
the second text line. This is not "inheritance" so much as it is whatever the |
314
|
|
|
|
|
|
|
graphics (drawing) state (used for both "graphics" and "text") is left in at |
315
|
|
|
|
|
|
|
the end of one object, it's the state at the beginning of the next object. |
316
|
|
|
|
|
|
|
If you wish to control this, consider surrounding the graphics or text calls |
317
|
|
|
|
|
|
|
with C and C calls to save and restore (push and pop) the |
318
|
|
|
|
|
|
|
graphics state to what it was at the C. Finally, the bar is drawn over |
319
|
|
|
|
|
|
|
everything. |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
# ---------------------------- |
322
|
|
|
|
|
|
|
# 3. (2) again, with two graphics and two text objects |
323
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
my $text3 = $page->text(); |
325
|
|
|
|
|
|
|
my $grfx3 = $page->gfx(); |
326
|
|
|
|
|
|
|
$text3->font($fontTR, 20); # 20 pt Times Roman bold |
327
|
|
|
|
|
|
|
my $text4 = $page->text(); |
328
|
|
|
|
|
|
|
my $grfx4 = $page->gfx(); |
329
|
|
|
|
|
|
|
$text4->font($fontTR, 20); # 20 pt Times Roman bold |
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
$text3->fillcolor('black'); |
332
|
|
|
|
|
|
|
$grfx3->strokecolor('blue'); |
333
|
|
|
|
|
|
|
$grfx3->fillcolor('orange'); |
334
|
|
|
|
|
|
|
# $text4->fillcolor('yellow'); |
335
|
|
|
|
|
|
|
# $grfx4->strokecolor('red'); |
336
|
|
|
|
|
|
|
# $grfx4->fillcolor('purple'); |
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
$text3->translate(50,500); |
339
|
|
|
|
|
|
|
$text3->text_left("This text should be under everything."); |
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
$grfx3->circle(100,490, 30); |
342
|
|
|
|
|
|
|
$grfx3->fillstroke(); |
343
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
$text4->translate(50,470); |
345
|
|
|
|
|
|
|
$text4->text_left("This text should be over the ball and under the bar."); |
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
$grfx4->rect(160,460, 20,70); |
348
|
|
|
|
|
|
|
$grfx4->fillstroke(); |
349
|
|
|
|
|
|
|
|
350
|
|
|
|
|
|
|
% ---------------- group 3: define text1, graphics1, text2, graphics2 |
351
|
|
|
|
|
|
|
15 0 obj << /Length 206 >> stream % obj 15 is text1 for (3) |
352
|
|
|
|
|
|
|
BT |
353
|
|
|
|
|
|
|
/TiCBA 20 Tf % Times Roman Bold 20pt |
354
|
|
|
|
|
|
|
0 0 0 rg % fill black |
355
|
|
|
|
|
|
|
1 0 0 1 50 500 Tm % position text |
356
|
|
|
|
|
|
|
<0037 ... 0011> Tj % "under" line |
357
|
|
|
|
|
|
|
ET |
358
|
|
|
|
|
|
|
endstream endobj |
359
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
16 0 obj << /Length 671 >> stream % obj 16 is graphics1 for (3) circle |
361
|
|
|
|
|
|
|
0 0 1 RG % stroke blue |
362
|
|
|
|
|
|
|
1 0.647059 0 rg % fill orange |
363
|
|
|
|
|
|
|
130 490 m ... h B % draw and fill circle |
364
|
|
|
|
|
|
|
endstream endobj |
365
|
|
|
|
|
|
|
|
366
|
|
|
|
|
|
|
17 0 obj << /Length 257 >> stream % obj 17 is text2 for (3) |
367
|
|
|
|
|
|
|
BT |
368
|
|
|
|
|
|
|
/TiCBA 20 Tf % Times Roman Bold 20pt |
369
|
|
|
|
|
|
|
1 0 0 1 50 470 Tm % position text |
370
|
|
|
|
|
|
|
<0037 ... 0011> Tj % "over" line |
371
|
|
|
|
|
|
|
ET |
372
|
|
|
|
|
|
|
endstream endobj |
373
|
|
|
|
|
|
|
|
374
|
|
|
|
|
|
|
18 0 obj << /Length 20 >> stream % obj 18 is graphics for (3) bar |
375
|
|
|
|
|
|
|
160 460 20 70 re B % draw and fill bar |
376
|
|
|
|
|
|
|
endstream endobj |
377
|
|
|
|
|
|
|
|
378
|
|
|
|
|
|
|
The fourth group is the same as the third, except that we define the fill color |
379
|
|
|
|
|
|
|
for the text in the second line. This makes it clear that the "over" line (in |
380
|
|
|
|
|
|
|
yellow) was written I the orange disc, and still before the bar. |
381
|
|
|
|
|
|
|
|
382
|
|
|
|
|
|
|
# ---------------------------- |
383
|
|
|
|
|
|
|
# 4. (3) again, a new set of colors for second group |
384
|
|
|
|
|
|
|
|
385
|
|
|
|
|
|
|
my $text3 = $page->text(); |
386
|
|
|
|
|
|
|
my $grfx3 = $page->gfx(); |
387
|
|
|
|
|
|
|
$text3->font($fontTR, 20); # 20 pt Times Roman bold |
388
|
|
|
|
|
|
|
my $text4 = $page->text(); |
389
|
|
|
|
|
|
|
my $grfx4 = $page->gfx(); |
390
|
|
|
|
|
|
|
$text4->font($fontTR, 20); # 20 pt Times Roman bold |
391
|
|
|
|
|
|
|
|
392
|
|
|
|
|
|
|
$text3->fillcolor('black'); |
393
|
|
|
|
|
|
|
$grfx3->strokecolor('blue'); |
394
|
|
|
|
|
|
|
$grfx3->fillcolor('orange'); |
395
|
|
|
|
|
|
|
$text4->fillcolor('yellow'); |
396
|
|
|
|
|
|
|
$grfx4->strokecolor('red'); |
397
|
|
|
|
|
|
|
$grfx4->fillcolor('purple'); |
398
|
|
|
|
|
|
|
|
399
|
|
|
|
|
|
|
$text3->translate(50,400); |
400
|
|
|
|
|
|
|
$text3->text_left("This text should be under everything."); |
401
|
|
|
|
|
|
|
|
402
|
|
|
|
|
|
|
$grfx3->circle(100,390, 30); |
403
|
|
|
|
|
|
|
$grfx3->fillstroke(); |
404
|
|
|
|
|
|
|
|
405
|
|
|
|
|
|
|
$text4->translate(50,370); |
406
|
|
|
|
|
|
|
$text4->text_left("This text should be over the ball and under the bar."); |
407
|
|
|
|
|
|
|
|
408
|
|
|
|
|
|
|
$grfx4->rect(160,360, 20,70); |
409
|
|
|
|
|
|
|
$grfx4->fillstroke(); |
410
|
|
|
|
|
|
|
|
411
|
|
|
|
|
|
|
% ---------------- group 4: define text1, graphics1, text2, graphics2 with colors for 2 |
412
|
|
|
|
|
|
|
19 0 obj << /Length 206 >> stream % obj 19 is text1 for (4) |
413
|
|
|
|
|
|
|
BT |
414
|
|
|
|
|
|
|
/TiCBA 20 Tf % Times Roman Bold 20pt |
415
|
|
|
|
|
|
|
0 0 0 rg % fill black |
416
|
|
|
|
|
|
|
1 0 0 1 50 400 Tm % position text |
417
|
|
|
|
|
|
|
<0037 ... 0011> Tj % "under" line |
418
|
|
|
|
|
|
|
ET |
419
|
|
|
|
|
|
|
endstream endobj |
420
|
|
|
|
|
|
|
|
421
|
|
|
|
|
|
|
20 0 obj << /Length 671 >> stream % obj 20 is graphics1 for (4) circle |
422
|
|
|
|
|
|
|
0 0 1 RG % stroke blue |
423
|
|
|
|
|
|
|
1 0.647059 0 rg % fill orange |
424
|
|
|
|
|
|
|
130 390 m ... h B % draw and fill circle |
425
|
|
|
|
|
|
|
endstream endobj |
426
|
|
|
|
|
|
|
|
427
|
|
|
|
|
|
|
21 0 obj << /Length 266 >> stream % obj 21 is text2 for (4) |
428
|
|
|
|
|
|
|
BT |
429
|
|
|
|
|
|
|
/TiCBA 20 Tf % Times Roman Bold 20pt |
430
|
|
|
|
|
|
|
1 1 0 rg % fill yellow |
431
|
|
|
|
|
|
|
1 0 0 1 50 370 Tm % position text |
432
|
|
|
|
|
|
|
<0037 ... 0011> Tj % "over" line |
433
|
|
|
|
|
|
|
ET |
434
|
|
|
|
|
|
|
endstream endobj |
435
|
|
|
|
|
|
|
|
436
|
|
|
|
|
|
|
22 0 obj << /Length 52 >> stream % obj 22 is graphics for (4) bar |
437
|
|
|
|
|
|
|
1 0 0 RG % stroke red |
438
|
|
|
|
|
|
|
0.498039 0 0.498039 rg % fill purple |
439
|
|
|
|
|
|
|
160 360 20 70 re B % draw and fill rectangle (bar) |
440
|
|
|
|
|
|
|
endstream endobj |
441
|
|
|
|
|
|
|
|
442
|
|
|
|
|
|
|
# ---------------------------- |
443
|
|
|
|
|
|
|
$pdf->saveas("$fname.pdf"); |
444
|
|
|
|
|
|
|
|
445
|
|
|
|
|
|
|
The separation of text and graphics means that only some text methods are |
446
|
|
|
|
|
|
|
available in a graphics object, and only some graphics methods are available |
447
|
|
|
|
|
|
|
in a text object. There is much overlap, but they differ. There's really no |
448
|
|
|
|
|
|
|
reason the code couldn't have been written (in PDF::API2, or earlier) as |
449
|
|
|
|
|
|
|
outputting to a single object, which would keep everything in the same order as |
450
|
|
|
|
|
|
|
the method calls. An advantage would be less object and stream overhead in the |
451
|
|
|
|
|
|
|
PDF file. The only drawback might be that an object might more easily |
452
|
|
|
|
|
|
|
overflow and require splitting into multiple objects, but that should be rare. |
453
|
|
|
|
|
|
|
|
454
|
|
|
|
|
|
|
You should always be able to manually split an object by simply ending output |
455
|
|
|
|
|
|
|
to the first object, and picking up with output to the second object, I
|
456
|
|
|
|
|
|
|
as it was created immediately after the first object.> The graphics state at |
457
|
|
|
|
|
|
|
the end of the first object should be the initial state at the beginning of the |
458
|
|
|
|
|
|
|
second object. B use caution when dealing with text objects -- the |
459
|
|
|
|
|
|
|
PDF specification states that the Text matrices are I carried over from |
460
|
|
|
|
|
|
|
one object to the next (B resets them), so you may need to reset some |
461
|
|
|
|
|
|
|
settings. |
462
|
|
|
|
|
|
|
|
463
|
|
|
|
|
|
|
$grfx1 = $page->gfx(); |
464
|
|
|
|
|
|
|
$grfx2 = $page->gfx(); |
465
|
|
|
|
|
|
|
# write a huge amount of stuff to $grfx1 |
466
|
|
|
|
|
|
|
# write a huge amount of stuff to $grfx2, picking up where $grfx1 left off |
467
|
|
|
|
|
|
|
|
468
|
|
|
|
|
|
|
In any case, now that you understand the rendering order and how the order |
469
|
|
|
|
|
|
|
of object declarations affects it, how text and graphics are drawn can now be |
470
|
|
|
|
|
|
|
completely controlled as desired. There is really no need to add another "both" |
471
|
|
|
|
|
|
|
type object that will handle all graphics and text objects, as that would |
472
|
|
|
|
|
|
|
probably be a major code bloat for very little benefit. However, it could be |
473
|
|
|
|
|
|
|
considered in the future if there is a demonstrated need for it, such as |
474
|
|
|
|
|
|
|
serious PDF file size bloat due to the extra object overhead when interleaving |
475
|
|
|
|
|
|
|
text and graphics output. |
476
|
|
|
|
|
|
|
|
477
|
|
|
|
|
|
|
=head2 PDF Versions Supported |
478
|
|
|
|
|
|
|
|
479
|
|
|
|
|
|
|
When creating a PDF file using the functions in PDF::Builder, the output is |
480
|
|
|
|
|
|
|
marked as PDF 1.4. This does not mean that all I functionality up through |
481
|
|
|
|
|
|
|
1.4 is supported! There are almost surely features missing as far back as the |
482
|
|
|
|
|
|
|
PDF 1.0 standard. |
483
|
|
|
|
|
|
|
|
484
|
|
|
|
|
|
|
The big problem is when a PDF of version 1.5 or higher is imported or opened |
485
|
|
|
|
|
|
|
in PDF::Builder. If it contains content that is actually unsupported by this |
486
|
|
|
|
|
|
|
software, there is a chance that something will break. This does not guarantee |
487
|
|
|
|
|
|
|
that a PDF marked as "1.7" will go down in flames when read by PDF::Builder, |
488
|
|
|
|
|
|
|
or that a PDF written back out will break in a Reader, but the possibility is |
489
|
|
|
|
|
|
|
there. Much PDF writer software simply marks its output as the highest version |
490
|
|
|
|
|
|
|
of PDF at the time (usually 1.7), even if there is no content beyond, say, 1.2. |
491
|
|
|
|
|
|
|
There is I handling of PDF 1.5 items in PDF::Builder, such as cross |
492
|
|
|
|
|
|
|
reference streams, but support beyond 1.4 is very limited. All we can say is to |
493
|
|
|
|
|
|
|
be careful when handling PDFs whose version is above 1.4, and test thoroughly, |
494
|
|
|
|
|
|
|
as they may break at some point. |
495
|
|
|
|
|
|
|
|
496
|
|
|
|
|
|
|
PDF::Builder includes a simple version control mechanism, where the initial |
497
|
|
|
|
|
|
|
PDF version to be output (default 1.4) can be set by the programmer. Input |
498
|
|
|
|
|
|
|
PDFs greater than 1.4 (current output level) will receive a warning (can be |
499
|
|
|
|
|
|
|
suppressed) that the output level will be raised to that level. The use of PDF |
500
|
|
|
|
|
|
|
features greater than the current output level will likewise trigger a warning |
501
|
|
|
|
|
|
|
that the output level is to be raised to the necessary level. If this is not |
502
|
|
|
|
|
|
|
desired, you should avoid using those PDF features which are higher than the |
503
|
|
|
|
|
|
|
desired PDF output level. |
504
|
|
|
|
|
|
|
|
505
|
|
|
|
|
|
|
=head2 History |
506
|
|
|
|
|
|
|
|
507
|
|
|
|
|
|
|
PDF::API2 was originally written by Alfred Reibenschuh, derived from Martin |
508
|
|
|
|
|
|
|
Hosken's Text::PDF via the Text::PDF::API wrapper. |
509
|
|
|
|
|
|
|
In 2009, Otto Hirr started the PDF::API3 fork, but it never went anywhere. |
510
|
|
|
|
|
|
|
In 2011, PDF::API2 maintenance was taken over by Steve Simms. |
511
|
|
|
|
|
|
|
In 2017, PDF::Builder was forked by Phil M. Perry, who desired a more aggressive |
512
|
|
|
|
|
|
|
schedule of new features and bug fixes than Simms was providing, although some |
513
|
|
|
|
|
|
|
of Simms's work I been ported from PDF::API2. |
514
|
|
|
|
|
|
|
|
515
|
|
|
|
|
|
|
According to "pdfapi2_for_fun_and_profit_APW2005.pdf" (on |
516
|
|
|
|
|
|
|
http://pdfapi2.sourceforge.net, an unmaintained site), the history of PDF::API2 |
517
|
|
|
|
|
|
|
(the predecessor to PDF::Builder) goes as such: |
518
|
|
|
|
|
|
|
|
519
|
|
|
|
|
|
|
=over |
520
|
|
|
|
|
|
|
|
521
|
|
|
|
|
|
|
=item E E EE First Code implemented based on PDFlib-0.6 (AFPL) |
522
|
|
|
|
|
|
|
|
523
|
|
|
|
|
|
|
=item E E EE Changed to Text::PDF with a total rewrite as Text::PDF::API (procedural) |
524
|
|
|
|
|
|
|
|
525
|
|
|
|
|
|
|
=item E E EE Unmaintainable Code triggered rewrite into new Namespace PDF::API2 (object-oriented, LGPL) |
526
|
|
|
|
|
|
|
|
527
|
|
|
|
|
|
|
=item E E EE Object-Structure streamlined in 0.4x |
528
|
|
|
|
|
|
|
|
529
|
|
|
|
|
|
|
=back |
530
|
|
|
|
|
|
|
|
531
|
|
|
|
|
|
|
At Simms's request, the name of the new offering was changed from PDF::API4 |
532
|
|
|
|
|
|
|
to PDF::Builder, to reduce the chance of confusion due to parallel development. |
533
|
|
|
|
|
|
|
Perry's intent is to keep all internal methods as upwardly compatible with |
534
|
|
|
|
|
|
|
PDF::API2 as possible, although it is likely that there will be some drift |
535
|
|
|
|
|
|
|
(incompatibilities) over time. At least initially, any program written based on |
536
|
|
|
|
|
|
|
PDF::API2 should be convertible to PDF::Builder simply by changing "API2" |
537
|
|
|
|
|
|
|
anywhere it occurs to "Builder". See the INFO/KNOWN_INCOMP known |
538
|
|
|
|
|
|
|
incompatibilities file for further information. |
539
|
|
|
|
|
|
|
|
540
|
|
|
|
|
|
|
=head3 Thanks... |
541
|
|
|
|
|
|
|
|
542
|
|
|
|
|
|
|
Many users have helped out by reporting bugs and requesting enhancements. A |
543
|
|
|
|
|
|
|
special shout out goes to those who have contributed code and tests, or |
544
|
|
|
|
|
|
|
coordinated their package development with the needs of PDF::Builder: |
545
|
|
|
|
|
|
|
Ben Bullock, Cary Gravel, Gregor Herrmann, Petr Pisar, Jeffrey Ratcliffe, |
546
|
|
|
|
|
|
|
Steve Simms (via PDF::API2 fixes), and Johan Vromans. |
547
|
|
|
|
|
|
|
Drop me a line if I've overlooked your contribution! |
548
|
|
|
|
|
|
|
|
549
|
|
|
|
|
|
|
=head1 DETAILED NOTES ON METHODS |
550
|
|
|
|
|
|
|
|
551
|
|
|
|
|
|
|
B older versions of this package named various (hash element) options |
552
|
|
|
|
|
|
|
with leading dashes (hyphens) in the name, e.g., '-encode'. The use of a dash |
553
|
|
|
|
|
|
|
is now optional, and options are documented with names I using dashes. At |
554
|
|
|
|
|
|
|
some point in the future, it is possible that support for dashed names will be |
555
|
|
|
|
|
|
|
deprecated (and eventually withdrawn), so it would be good practice to start |
556
|
|
|
|
|
|
|
using undashed names in new and revised code. |
557
|
|
|
|
|
|
|
|
558
|
|
|
|
|
|
|
=head2 After saving a file... |
559
|
|
|
|
|
|
|
|
560
|
|
|
|
|
|
|
Note that a PDF object such as C<$pdf> cannot continue to be used after saving |
561
|
|
|
|
|
|
|
an output PDF file or string with $pdf->C, C, or |
562
|
|
|
|
|
|
|
C. There is some cleanup and other operations done internally |
563
|
|
|
|
|
|
|
which make the object unusable for further operations. You will likely receive |
564
|
|
|
|
|
|
|
an error message about B if |
565
|
|
|
|
|
|
|
you try to keep using a PDF object. |
566
|
|
|
|
|
|
|
|
567
|
|
|
|
|
|
|
=head2 IntegrityCheck |
568
|
|
|
|
|
|
|
|
569
|
|
|
|
|
|
|
The PDF::Builder methods that open an existing PDF file, pass it by the |
570
|
|
|
|
|
|
|
integrity checker method, C<$self-EIntegrityCheck(level, content)>. This method |
571
|
|
|
|
|
|
|
servers two purposes: 1) to find any C settings that override the |
572
|
|
|
|
|
|
|
PDF version found in the PDF heading, and 2) perform some basic validations on |
573
|
|
|
|
|
|
|
the contents of the PDF. |
574
|
|
|
|
|
|
|
|
575
|
|
|
|
|
|
|
The C parameter accepts the following values: |
576
|
|
|
|
|
|
|
|
577
|
|
|
|
|
|
|
=over |
578
|
|
|
|
|
|
|
|
579
|
|
|
|
|
|
|
=item 0 = Do not output any diagnostic messages; just return any version override. |
580
|
|
|
|
|
|
|
|
581
|
|
|
|
|
|
|
=item 1 = Output error-level (serious) diagnostic messages, as well as returning any version override. |
582
|
|
|
|
|
|
|
|
583
|
|
|
|
|
|
|
Errors include, in no place was the /Root object specified, or if it was, the indicated object was not found. An object claims another object as its child (/Kids list), but another object has already claimed that child. An object claims a child, but that child does not list a Parent, or the child lists a different Parent. |
584
|
|
|
|
|
|
|
|
585
|
|
|
|
|
|
|
=item 2 = Output error- (serious) and warning- (less serious) level diagnostic messages, as well as returning any version override. B |
586
|
|
|
|
|
|
|
|
587
|
|
|
|
|
|
|
=item 3 = Output error- (serious), warning- (less serious), and note- (informational) level diagnostic messages, as well as returning any version override. |
588
|
|
|
|
|
|
|
|
589
|
|
|
|
|
|
|
Notes include, in no place was the (optional) /Info object specified, or if it was, the indicated object was not found. An object was referenced, but no entry for it was found among the objects. (This may be OK if the object is not defined, or is on the free list, as the reference will then be ignored.) An object is defined, but it appears that no other object is referencing it. |
590
|
|
|
|
|
|
|
|
591
|
|
|
|
|
|
|
=item 4 = Output error-, warning-, and note-level diagnostic messages, as well as returning any version override. Also dump the diagnostic data structure. |
592
|
|
|
|
|
|
|
|
593
|
|
|
|
|
|
|
=item 5 = Output error-, warning-, and note-level diagnostic messages, as well as returning any version override. Also dump the diagnostic data structure and the C<$self> data structure (generally useful only if you have already read in the PDF file). |
594
|
|
|
|
|
|
|
|
595
|
|
|
|
|
|
|
=back |
596
|
|
|
|
|
|
|
|
597
|
|
|
|
|
|
|
The version is a string (e.g., '1.5') if found, otherwise C (undefined value) is returned. |
598
|
|
|
|
|
|
|
|
599
|
|
|
|
|
|
|
For controlling the "automatic" call to IntegrityCheck (via opens), the level |
600
|
|
|
|
|
|
|
may be given with the option (flag) C I>, where C is between 0 and 5. |
601
|
|
|
|
|
|
|
|
602
|
|
|
|
|
|
|
=head2 Preferences - set user display preferences |
603
|
|
|
|
|
|
|
|
604
|
|
|
|
|
|
|
=over |
605
|
|
|
|
|
|
|
|
606
|
|
|
|
|
|
|
=item $pdf->preferences(%options) |
607
|
|
|
|
|
|
|
|
608
|
|
|
|
|
|
|
Controls viewing preferences for the PDF. |
609
|
|
|
|
|
|
|
|
610
|
|
|
|
|
|
|
=back |
611
|
|
|
|
|
|
|
|
612
|
|
|
|
|
|
|
=head3 Page Mode Options |
613
|
|
|
|
|
|
|
|
614
|
|
|
|
|
|
|
=over |
615
|
|
|
|
|
|
|
|
616
|
|
|
|
|
|
|
=over |
617
|
|
|
|
|
|
|
|
618
|
|
|
|
|
|
|
=item fullscreen |
619
|
|
|
|
|
|
|
|
620
|
|
|
|
|
|
|
Full-screen mode, with no menu bar, window controls, or any other window visible. |
621
|
|
|
|
|
|
|
|
622
|
|
|
|
|
|
|
=item thumbs |
623
|
|
|
|
|
|
|
|
624
|
|
|
|
|
|
|
Thumbnail images visible. |
625
|
|
|
|
|
|
|
|
626
|
|
|
|
|
|
|
=item outlines |
627
|
|
|
|
|
|
|
|
628
|
|
|
|
|
|
|
Document outline visible. |
629
|
|
|
|
|
|
|
|
630
|
|
|
|
|
|
|
=back |
631
|
|
|
|
|
|
|
|
632
|
|
|
|
|
|
|
=back |
633
|
|
|
|
|
|
|
|
634
|
|
|
|
|
|
|
=head3 Page Layout Options |
635
|
|
|
|
|
|
|
|
636
|
|
|
|
|
|
|
=over |
637
|
|
|
|
|
|
|
|
638
|
|
|
|
|
|
|
=over |
639
|
|
|
|
|
|
|
|
640
|
|
|
|
|
|
|
=item singlepage |
641
|
|
|
|
|
|
|
|
642
|
|
|
|
|
|
|
Display one page at a time. |
643
|
|
|
|
|
|
|
|
644
|
|
|
|
|
|
|
=item onecolumn |
645
|
|
|
|
|
|
|
|
646
|
|
|
|
|
|
|
Display the pages in one column. |
647
|
|
|
|
|
|
|
|
648
|
|
|
|
|
|
|
=item twocolumnleft |
649
|
|
|
|
|
|
|
|
650
|
|
|
|
|
|
|
Display the pages in two columns, with oddnumbered pages on the left. |
651
|
|
|
|
|
|
|
|
652
|
|
|
|
|
|
|
=item twocolumnright |
653
|
|
|
|
|
|
|
|
654
|
|
|
|
|
|
|
Display the pages in two columns, with oddnumbered pages on the right. |
655
|
|
|
|
|
|
|
|
656
|
|
|
|
|
|
|
=back |
657
|
|
|
|
|
|
|
|
658
|
|
|
|
|
|
|
=back |
659
|
|
|
|
|
|
|
|
660
|
|
|
|
|
|
|
=head3 Viewer Options |
661
|
|
|
|
|
|
|
|
662
|
|
|
|
|
|
|
=over |
663
|
|
|
|
|
|
|
|
664
|
|
|
|
|
|
|
=over |
665
|
|
|
|
|
|
|
|
666
|
|
|
|
|
|
|
=item hidetoolbar |
667
|
|
|
|
|
|
|
|
668
|
|
|
|
|
|
|
Specifying whether to hide tool bars. |
669
|
|
|
|
|
|
|
|
670
|
|
|
|
|
|
|
=item hidemenubar |
671
|
|
|
|
|
|
|
|
672
|
|
|
|
|
|
|
Specifying whether to hide menu bars. |
673
|
|
|
|
|
|
|
|
674
|
|
|
|
|
|
|
=item hidewindowui |
675
|
|
|
|
|
|
|
|
676
|
|
|
|
|
|
|
Specifying whether to hide user interface elements. |
677
|
|
|
|
|
|
|
|
678
|
|
|
|
|
|
|
=item fitwindow |
679
|
|
|
|
|
|
|
|
680
|
|
|
|
|
|
|
Specifying whether to resize the document's window to the size of the displayed page. |
681
|
|
|
|
|
|
|
|
682
|
|
|
|
|
|
|
=item centerwindow |
683
|
|
|
|
|
|
|
|
684
|
|
|
|
|
|
|
Specifying whether to position the document's window in the center of the screen. |
685
|
|
|
|
|
|
|
|
686
|
|
|
|
|
|
|
=item displaytitle |
687
|
|
|
|
|
|
|
|
688
|
|
|
|
|
|
|
Specifying whether the window's title bar should display the |
689
|
|
|
|
|
|
|
document title taken from the Title entry of the document information |
690
|
|
|
|
|
|
|
dictionary. |
691
|
|
|
|
|
|
|
|
692
|
|
|
|
|
|
|
=item afterfullscreenthumbs |
693
|
|
|
|
|
|
|
|
694
|
|
|
|
|
|
|
Thumbnail images visible after Full-screen mode. |
695
|
|
|
|
|
|
|
|
696
|
|
|
|
|
|
|
=item afterfullscreenoutlines |
697
|
|
|
|
|
|
|
|
698
|
|
|
|
|
|
|
Document outline visible after Full-screen mode. |
699
|
|
|
|
|
|
|
|
700
|
|
|
|
|
|
|
=item printscalingnone |
701
|
|
|
|
|
|
|
|
702
|
|
|
|
|
|
|
Set the default print setting for page scaling to none. |
703
|
|
|
|
|
|
|
|
704
|
|
|
|
|
|
|
=item simplex |
705
|
|
|
|
|
|
|
|
706
|
|
|
|
|
|
|
Print single-sided by default. |
707
|
|
|
|
|
|
|
|
708
|
|
|
|
|
|
|
=item duplexflipshortedge |
709
|
|
|
|
|
|
|
|
710
|
|
|
|
|
|
|
Print duplex by default and flip on the short edge of the sheet. |
711
|
|
|
|
|
|
|
|
712
|
|
|
|
|
|
|
=item duplexfliplongedge |
713
|
|
|
|
|
|
|
|
714
|
|
|
|
|
|
|
Print duplex by default and flip on the long edge of the sheet. |
715
|
|
|
|
|
|
|
|
716
|
|
|
|
|
|
|
=back |
717
|
|
|
|
|
|
|
|
718
|
|
|
|
|
|
|
=back |
719
|
|
|
|
|
|
|
|
720
|
|
|
|
|
|
|
=head3 Page Fit Options |
721
|
|
|
|
|
|
|
|
722
|
|
|
|
|
|
|
These options are used for the C layout, as well as for |
723
|
|
|
|
|
|
|
Annotations, Named Destinations and Outlines. |
724
|
|
|
|
|
|
|
|
725
|
|
|
|
|
|
|
=over |
726
|
|
|
|
|
|
|
|
727
|
|
|
|
|
|
|
=item 'fit' => 1 |
728
|
|
|
|
|
|
|
|
729
|
|
|
|
|
|
|
Display the page designated by C<$page>, with its contents magnified just |
730
|
|
|
|
|
|
|
enough to fit the entire page within the window both horizontally and |
731
|
|
|
|
|
|
|
vertically. If the required horizontal and vertical magnification |
732
|
|
|
|
|
|
|
factors are different, use the smaller of the two, centering the page |
733
|
|
|
|
|
|
|
within the window in the other dimension. |
734
|
|
|
|
|
|
|
|
735
|
|
|
|
|
|
|
=item 'fith' => $top |
736
|
|
|
|
|
|
|
|
737
|
|
|
|
|
|
|
Display the page designated by C<$page>, with the vertical coordinate C<$top> |
738
|
|
|
|
|
|
|
positioned at the top edge of the window and the contents of the page |
739
|
|
|
|
|
|
|
magnified just enough to fit the entire width of the page within the |
740
|
|
|
|
|
|
|
window. |
741
|
|
|
|
|
|
|
|
742
|
|
|
|
|
|
|
=item 'fitv' => $left |
743
|
|
|
|
|
|
|
|
744
|
|
|
|
|
|
|
Display the page designated by C<$page>, with the horizontal coordinate |
745
|
|
|
|
|
|
|
C<$left> positioned at the left edge of the window and the contents of the |
746
|
|
|
|
|
|
|
page magnified just enough to fit the entire height of the page within |
747
|
|
|
|
|
|
|
the window. |
748
|
|
|
|
|
|
|
|
749
|
|
|
|
|
|
|
=item 'fitr' => [ $left, $bottom, $right, $top ] |
750
|
|
|
|
|
|
|
|
751
|
|
|
|
|
|
|
Display the page designated by C<$page>, with its contents magnified just |
752
|
|
|
|
|
|
|
enough to fit the rectangle specified by the coordinates C<$left>, C<$bottom>, |
753
|
|
|
|
|
|
|
C<$right>, and C<$top> entirely within the window both horizontally and |
754
|
|
|
|
|
|
|
vertically. If the required horizontal and vertical magnification |
755
|
|
|
|
|
|
|
factors are different, use the smaller of the two, centering the |
756
|
|
|
|
|
|
|
rectangle within the window in the other dimension. |
757
|
|
|
|
|
|
|
|
758
|
|
|
|
|
|
|
=item 'fitb' => 1 |
759
|
|
|
|
|
|
|
|
760
|
|
|
|
|
|
|
Display the page designated by C<$page>, with its contents magnified just |
761
|
|
|
|
|
|
|
enough to fit its bounding box entirely within the window both |
762
|
|
|
|
|
|
|
horizontally and vertically. If the required horizontal and vertical |
763
|
|
|
|
|
|
|
magnification factors are different, use the smaller of the two, |
764
|
|
|
|
|
|
|
centering the bounding box within the window in the other dimension. |
765
|
|
|
|
|
|
|
|
766
|
|
|
|
|
|
|
=item 'fitbh' => $top |
767
|
|
|
|
|
|
|
|
768
|
|
|
|
|
|
|
Display the page designated by C<$page>, with the vertical coordinate C<$top> |
769
|
|
|
|
|
|
|
positioned at the top edge of the window and the contents of the page |
770
|
|
|
|
|
|
|
magnified just enough to fit the entire width of its bounding box |
771
|
|
|
|
|
|
|
within the window. |
772
|
|
|
|
|
|
|
|
773
|
|
|
|
|
|
|
=item 'fitbv' => $left |
774
|
|
|
|
|
|
|
|
775
|
|
|
|
|
|
|
Display the page designated by C<$page>, with the horizontal coordinate |
776
|
|
|
|
|
|
|
C<$left> positioned at the left edge of the window and the contents of the |
777
|
|
|
|
|
|
|
page magnified just enough to fit the entire height of its bounding |
778
|
|
|
|
|
|
|
box within the window. |
779
|
|
|
|
|
|
|
|
780
|
|
|
|
|
|
|
=item 'xyz' => [ $left, $top, $zoom ] |
781
|
|
|
|
|
|
|
|
782
|
|
|
|
|
|
|
Display the page designated by C<$page>, with the coordinates C<$[$left, $top]> |
783
|
|
|
|
|
|
|
positioned at the top-left corner of the window and the contents of |
784
|
|
|
|
|
|
|
the page magnified by the factor C<$zoom>. A zero (0) value for any of the |
785
|
|
|
|
|
|
|
parameters C<$left>, C<$top>, or C<$zoom> specifies that the current value of |
786
|
|
|
|
|
|
|
that parameter is to be retained unchanged. |
787
|
|
|
|
|
|
|
|
788
|
|
|
|
|
|
|
=back |
789
|
|
|
|
|
|
|
|
790
|
|
|
|
|
|
|
=head3 Initial Page Options |
791
|
|
|
|
|
|
|
|
792
|
|
|
|
|
|
|
=over |
793
|
|
|
|
|
|
|
|
794
|
|
|
|
|
|
|
=item firstpage => [ $page, %options ] |
795
|
|
|
|
|
|
|
|
796
|
|
|
|
|
|
|
Specifying the page (either a page number or a page object) to be |
797
|
|
|
|
|
|
|
displayed, plus one of the location options listed above in L. |
798
|
|
|
|
|
|
|
|
799
|
|
|
|
|
|
|
=back |
800
|
|
|
|
|
|
|
|
801
|
|
|
|
|
|
|
=head3 Example |
802
|
|
|
|
|
|
|
|
803
|
|
|
|
|
|
|
$pdf->preferences( |
804
|
|
|
|
|
|
|
fullscreen => 1, |
805
|
|
|
|
|
|
|
onecolumn => 1, |
806
|
|
|
|
|
|
|
afterfullscreenoutlines => 1, |
807
|
|
|
|
|
|
|
firstpage => [$page, fit => 1], |
808
|
|
|
|
|
|
|
); |
809
|
|
|
|
|
|
|
|
810
|
|
|
|
|
|
|
=head2 info Example |
811
|
|
|
|
|
|
|
|
812
|
|
|
|
|
|
|
%h = $pdf->info( |
813
|
|
|
|
|
|
|
'Author' => "Alfred Reibenschuh", |
814
|
|
|
|
|
|
|
'CreationDate' => "D:20020911000000+01'00'", |
815
|
|
|
|
|
|
|
'ModDate' => "D:YYYYMMDDhhmmssOHH'mm'", |
816
|
|
|
|
|
|
|
'Creator' => "fredos-script.pl", |
817
|
|
|
|
|
|
|
'Producer' => "PDF::Builder", |
818
|
|
|
|
|
|
|
'Title' => "some Publication", |
819
|
|
|
|
|
|
|
'Subject' => "perl ?", |
820
|
|
|
|
|
|
|
'Keywords' => "all good things are pdf" |
821
|
|
|
|
|
|
|
); |
822
|
|
|
|
|
|
|
print "Author: $h{'Author'}\n"; |
823
|
|
|
|
|
|
|
|
824
|
|
|
|
|
|
|
=head2 XMP XML example |
825
|
|
|
|
|
|
|
|
826
|
|
|
|
|
|
|
$xml = $pdf->xmpMetadata(); |
827
|
|
|
|
|
|
|
print "PDFs Metadata reads: $xml\n"; |
828
|
|
|
|
|
|
|
$xml=<
|
829
|
|
|
|
|
|
|
|
830
|
|
|
|
|
|
|
|
831
|
|
|
|
|
|
|
|
832
|
|
|
|
|
|
|
xmlns:x='adobe:ns:meta/' |
833
|
|
|
|
|
|
|
x:xmptk='XMP toolkit 2.9.1-14, framework 1.6'> |
834
|
|
|
|
|
|
|
|
835
|
|
|
|
|
|
|
xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' |
836
|
|
|
|
|
|
|
xmlns:iX='http://ns.adobe.com/iX/1.0/'> |
837
|
|
|
|
|
|
|
|
838
|
|
|
|
|
|
|
rdf:about='uuid:b8659d3a-369e-11d9-b951-000393c97fd8' |
839
|
|
|
|
|
|
|
xmlns:pdf='http://ns.adobe.com/pdf/1.3/' |
840
|
|
|
|
|
|
|
pdf:Producer='Acrobat Distiller 6.0.1 for Macintosh'> |
841
|
|
|
|
|
|
|
|
842
|
|
|
|
|
|
|
rdf:about='uuid:b8659d3a-369e-11d9-b951-000393c97fd8' |
843
|
|
|
|
|
|
|
xmlns:xap='http://ns.adobe.com/xap/1.0/' |
844
|
|
|
|
|
|
|
xap:CreateDate='2004-11-14T08:41:16Z' |
845
|
|
|
|
|
|
|
xap:ModifyDate='2004-11-14T16:38:50-08:00' |
846
|
|
|
|
|
|
|
xap:CreatorTool='FrameMaker 7.0' |
847
|
|
|
|
|
|
|
xap:MetadataDate='2004-11-14T16:38:50-08:00'> |
848
|
|
|
|
|
|
|
|
849
|
|
|
|
|
|
|
rdf:about='uuid:b8659d3a-369e-11d9-b951-000393c97fd8' |
850
|
|
|
|
|
|
|
xmlns:xapMM='http://ns.adobe.com/xap/1.0/mm/' |
851
|
|
|
|
|
|
|
xapMM:DocumentID='uuid:919b9378-369c-11d9-a2b5-000393c97fd8'/> |
852
|
|
|
|
|
|
|
|
853
|
|
|
|
|
|
|
rdf:about='uuid:b8659d3a-369e-11d9-b951-000393c97fd8' |
854
|
|
|
|
|
|
|
xmlns:dc='http://purl.org/dc/elements/1.1/' |
855
|
|
|
|
|
|
|
dc:format='application/pdf'> |
856
|
|
|
|
|
|
|
|
857
|
|
|
|
|
|
|
|
858
|
|
|
|
|
|
|
Adobe Portable Document Format (PDF) |
859
|
|
|
|
|
|
|
|
860
|
|
|
|
|
|
|
|
861
|
|
|
|
|
|
|
|
862
|
|
|
|
|
|
|
|
863
|
|
|
|
|
|
|
Adobe Systems Incorporated |
864
|
|
|
|
|
|
|
|
865
|
|
|
|
|
|
|
|
866
|
|
|
|
|
|
|
|
867
|
|
|
|
|
|
|
|
868
|
|
|
|
|
|
|
PDF Reference, version 1.6 |
869
|
|
|
|
|
|
|
|
870
|
|
|
|
|
|
|
|
871
|
|
|
|
|
|
|
|
872
|
|
|
|
|
|
|
|
873
|
|
|
|
|
|
|
|
874
|
|
|
|
|
|
|
|
875
|
|
|
|
|
|
|
EOT |
876
|
|
|
|
|
|
|
|
877
|
|
|
|
|
|
|
$xml = $pdf->xmpMetadata($xml); |
878
|
|
|
|
|
|
|
print "PDF metadata now reads: $xml\n"; |
879
|
|
|
|
|
|
|
|
880
|
|
|
|
|
|
|
=head2 "BOX" METHODS |
881
|
|
|
|
|
|
|
|
882
|
|
|
|
|
|
|
B Use care if specifying a different Media Box (or other "box") |
883
|
|
|
|
|
|
|
for a page, than the global "box" setting, to define the whole "chain" of boxes |
884
|
|
|
|
|
|
|
on the page, to avoid surprises. For example, to define a global Media Box |
885
|
|
|
|
|
|
|
(paper size) and a global Crop Box, and then define a new page-level Media Box |
886
|
|
|
|
|
|
|
I defining a new page-level Crop Box, may give odd results in the |
887
|
|
|
|
|
|
|
resultant cropping. Such combinations are not well defined. |
888
|
|
|
|
|
|
|
|
889
|
|
|
|
|
|
|
All dimensions in boxes default to the default User Unit, which is points (1/72 |
890
|
|
|
|
|
|
|
inch). Note that the PDF specification limits sizes and coordinates to 14400 |
891
|
|
|
|
|
|
|
User Units (200 inches, for the default User Unit of one point), and Adobe |
892
|
|
|
|
|
|
|
products (so far) follow this limit for Acrobat and Distiller. It is worth |
893
|
|
|
|
|
|
|
noting that other PDF writers and readers may choose to ignore the 14400 unit |
894
|
|
|
|
|
|
|
limit, with or without the use of a specified User Unit. Therefore, PDF::Builder |
895
|
|
|
|
|
|
|
does not enforce any limits on coordinates -- it's I responsibility to |
896
|
|
|
|
|
|
|
consider what readers and other PDF tools may be used with a PDF you produce! |
897
|
|
|
|
|
|
|
Also note that earlier Acrobat readers had coordinate limits as small as 3240 |
898
|
|
|
|
|
|
|
User Units (45 inches), and I media size of 72 or 3 User Units. |
899
|
|
|
|
|
|
|
|
900
|
|
|
|
|
|
|
=head3 User Units |
901
|
|
|
|
|
|
|
|
902
|
|
|
|
|
|
|
=over |
903
|
|
|
|
|
|
|
|
904
|
|
|
|
|
|
|
=item $pdf->userunit($number) |
905
|
|
|
|
|
|
|
|
906
|
|
|
|
|
|
|
The default User Unit in the PDF coordinate system is one point (1/72 inch). You |
907
|
|
|
|
|
|
|
can think of it as a scale factor to enable larger (or even, smaller) documents. |
908
|
|
|
|
|
|
|
This method may be used (for PDF 1.6 and higher) to set the User Unit to some |
909
|
|
|
|
|
|
|
number of points. For example, C will set the scale multiplier to |
910
|
|
|
|
|
|
|
72.0 points per User Unit, or 1 inch to the User Unit. Any number greater than |
911
|
|
|
|
|
|
|
zero is acceptable, although some readers and tools may not handle User Units of |
912
|
|
|
|
|
|
|
less than 1.0 very well. |
913
|
|
|
|
|
|
|
|
914
|
|
|
|
|
|
|
Not all readers respect the User Unit, if you give one, or handle it in exactly |
915
|
|
|
|
|
|
|
the same way. Adobe Distiller, for one, does not use it. How User Units are |
916
|
|
|
|
|
|
|
handled may vary from reader to reader. Adobe Acrobat, at this writing, respects |
917
|
|
|
|
|
|
|
User Unit in version 7.0 and up, but limits it to 75000 (giving a maximum |
918
|
|
|
|
|
|
|
document size of 15 million inches or 236.7 miles or 381 km). Other readers and |
919
|
|
|
|
|
|
|
PDF tools may allow a larger (or smaller) limit. |
920
|
|
|
|
|
|
|
|
921
|
|
|
|
|
|
|
B Some readers ignore a global |
922
|
|
|
|
|
|
|
User Unit setting and do I have pages inherit it (PDF::Builder duplicates |
923
|
|
|
|
|
|
|
it on each page to simulate inheritance). Some readers may give spurious |
924
|
|
|
|
|
|
|
warnings about truncated content when a Media Box is changed while User Units |
925
|
|
|
|
|
|
|
are being used. Some readers do strange things with Crop Boxes when a User Unit |
926
|
|
|
|
|
|
|
is in effect. |
927
|
|
|
|
|
|
|
|
928
|
|
|
|
|
|
|
Depending on the reader used, the effect of a larger User Unit (greater than 1) |
929
|
|
|
|
|
|
|
may mean lower resolution (chunkier or coarser appearance) in the rendered |
930
|
|
|
|
|
|
|
document. If you're printing something the size of a highway billboard, this may |
931
|
|
|
|
|
|
|
not matter to you, but you should be aware of the possibility (even with |
932
|
|
|
|
|
|
|
fractional coordinates). Conversely, a User Unit of less than 1.0 (if permitted) |
933
|
|
|
|
|
|
|
reduces the allowable size of your document, but I result in greater |
934
|
|
|
|
|
|
|
resolution. |
935
|
|
|
|
|
|
|
|
936
|
|
|
|
|
|
|
A global (PDF level) User Unit setting is inherited by each page (an action by |
937
|
|
|
|
|
|
|
PDF::Builder, not necessarily automatically done by the reader), or can be |
938
|
|
|
|
|
|
|
overridden by calling userunit in the page. Do not give more than one global |
939
|
|
|
|
|
|
|
userunit setting, as only the last one will be used. |
940
|
|
|
|
|
|
|
Setting a page's User Unit (if C<< $page-> >> instead) is permitted (overriding |
941
|
|
|
|
|
|
|
the global setting for this page). However, many sources recommend against |
942
|
|
|
|
|
|
|
doing this, as results may not be as expected (once again, depending on the |
943
|
|
|
|
|
|
|
quirks of the reader). |
944
|
|
|
|
|
|
|
|
945
|
|
|
|
|
|
|
Remember to call C I calling anything having to do with page |
946
|
|
|
|
|
|
|
or box sizes, or coordinates. Especially when setting 'named' box sizes, the |
947
|
|
|
|
|
|
|
methods need to know the current User Unit so that named page sizes (in points) |
948
|
|
|
|
|
|
|
may be scaled down to the current User Unit. |
949
|
|
|
|
|
|
|
|
950
|
|
|
|
|
|
|
=back |
951
|
|
|
|
|
|
|
|
952
|
|
|
|
|
|
|
=head3 Media Box |
953
|
|
|
|
|
|
|
|
954
|
|
|
|
|
|
|
=over |
955
|
|
|
|
|
|
|
|
956
|
|
|
|
|
|
|
=item $pdf->mediabox($name) |
957
|
|
|
|
|
|
|
|
958
|
|
|
|
|
|
|
=item $pdf->mediabox($name, orient => 'orientation' ) |
959
|
|
|
|
|
|
|
|
960
|
|
|
|
|
|
|
=item $pdf->mediabox($w,$h) |
961
|
|
|
|
|
|
|
|
962
|
|
|
|
|
|
|
=item $pdf->mediabox($llx,$lly, $urx,$ury) |
963
|
|
|
|
|
|
|
|
964
|
|
|
|
|
|
|
=item ($llx,$lly, $urx,$ury) = $pdf->mediabox() |
965
|
|
|
|
|
|
|
|
966
|
|
|
|
|
|
|
Sets the global Media Box (or page's Media Box, if C<< $page-> >> instead). |
967
|
|
|
|
|
|
|
This defines the width and height (or by corner |
968
|
|
|
|
|
|
|
coordinates, or by standard name) of the output page itself, such as the |
969
|
|
|
|
|
|
|
physical paper size. This is normally the largest of the "boxes". If any |
970
|
|
|
|
|
|
|
subsidiary box (within it) exceeds the media box, the portion of the material |
971
|
|
|
|
|
|
|
or boxes outside of the Media Box will be ignored. That is, the Media Box is |
972
|
|
|
|
|
|
|
the One Box to Rule Them All, and is the overall limit for other boxes (some |
973
|
|
|
|
|
|
|
documentation refers to the Media Box as "clipping" other boxes). In |
974
|
|
|
|
|
|
|
addition, the Media Box defines the overall I for text and |
975
|
|
|
|
|
|
|
graphics operations. |
976
|
|
|
|
|
|
|
|
977
|
|
|
|
|
|
|
If no arguments are given, the current Media Box (global or page) coordinates |
978
|
|
|
|
|
|
|
are returned instead. The former C (page only) function is |
979
|
|
|
|
|
|
|
B and will likely be removed some time in the future. In addition, |
980
|
|
|
|
|
|
|
when I the Media Box, the resulting coordinates are returned. This |
981
|
|
|
|
|
|
|
permits you to specify the page size by a name (alias) and get the dimensions |
982
|
|
|
|
|
|
|
back, all in one call. |
983
|
|
|
|
|
|
|
|
984
|
|
|
|
|
|
|
Note that many printers can B print all the way to the |
985
|
|
|
|
|
|
|
physical edge of the paper, so you should plan to leave some blank margin, |
986
|
|
|
|
|
|
|
even outside of any crop marks and bleeds. Printers and on-screen readers are |
987
|
|
|
|
|
|
|
free to discard any content found outside the Media Box, and printers may |
988
|
|
|
|
|
|
|
discard some material just inside the Media Box. |
989
|
|
|
|
|
|
|
|
990
|
|
|
|
|
|
|
A I Media Box is B by the PDF spec; if not explicitly given, |
991
|
|
|
|
|
|
|
PDF::Builder will set the global Media Box to US Letter size (8.5in x 11in). |
992
|
|
|
|
|
|
|
This is the media size that will be used for all pages if you do not specify |
993
|
|
|
|
|
|
|
a C call on a page. That is, |
994
|
|
|
|
|
|
|
a global (PDF level) mediabox setting is inherited by each page, or can be |
995
|
|
|
|
|
|
|
overridden by setting mediabox in the page. Do not give more than one global |
996
|
|
|
|
|
|
|
mediabox setting, as only the last one will be used. |
997
|
|
|
|
|
|
|
|
998
|
|
|
|
|
|
|
If you give a single string name (e.g., 'A4'), you may optionally add an |
999
|
|
|
|
|
|
|
orientation to turn the page 90 degrees into Landscape mode: |
1000
|
|
|
|
|
|
|
C<< orient => 'L' >> or C<< orient => 'l' >>. C is the only option |
1001
|
|
|
|
|
|
|
recognized, and a string beginning with an 'L' or 'l' (for Landscape) is the |
1002
|
|
|
|
|
|
|
only value of interest (anything else is treated as Portrait mode). The I |
1003
|
|
|
|
|
|
|
axis still runs from 0 at the bottom of the page to what used to be the page |
1004
|
|
|
|
|
|
|
I (now, I) at the top, and likewise for the I axis: 0 at left |
1005
|
|
|
|
|
|
|
to (former) I at the right. That is, the coordinate system is the same |
1006
|
|
|
|
|
|
|
as before, except that the height and width are different. |
1007
|
|
|
|
|
|
|
|
1008
|
|
|
|
|
|
|
The lower left corner does not I to be 0,0. It can be any values you want, |
1009
|
|
|
|
|
|
|
including negative values (so long as the resulting media's sides are at least |
1010
|
|
|
|
|
|
|
one point long). C sets the coordinate system (including the origin) |
1011
|
|
|
|
|
|
|
of the graphics and text that will be drawn, as well as for subsequent "boxes". |
1012
|
|
|
|
|
|
|
It's even possible to give any two opposite corners (such as upper left and |
1013
|
|
|
|
|
|
|
lower right). The coordinate system will be rearranged (by the Reader) to |
1014
|
|
|
|
|
|
|
still be the conventional minimum C and C in the lower left (i.e., you |
1015
|
|
|
|
|
|
|
can't make C I from top to bottom!). |
1016
|
|
|
|
|
|
|
|
1017
|
|
|
|
|
|
|
B |
1018
|
|
|
|
|
|
|
|
1019
|
|
|
|
|
|
|
$pdf = PDF::Builder->new(); |
1020
|
|
|
|
|
|
|
$pdf->mediabox('A4'); # A4 size (595 Pt wide by 842 Pt high) |
1021
|
|
|
|
|
|
|
... |
1022
|
|
|
|
|
|
|
$pdf->saveas('our/new.pdf'); |
1023
|
|
|
|
|
|
|
|
1024
|
|
|
|
|
|
|
$pdf = PDF::Builder->new(); |
1025
|
|
|
|
|
|
|
$pdf->mediabox(595, 842); # A4 size, with implicit 0,0 LL corner |
1026
|
|
|
|
|
|
|
... |
1027
|
|
|
|
|
|
|
$pdf->saveas('our/new.pdf'); |
1028
|
|
|
|
|
|
|
|
1029
|
|
|
|
|
|
|
$pdf = PDF::Builder->new; |
1030
|
|
|
|
|
|
|
$pdf->mediabox(0, 0, 595, 842); # A4 size, with explicit 0,0 LL corner |
1031
|
|
|
|
|
|
|
... |
1032
|
|
|
|
|
|
|
$pdf->saveas('our/new.pdf'); |
1033
|
|
|
|
|
|
|
|
1034
|
|
|
|
|
|
|
See the L source code for the full list of |
1035
|
|
|
|
|
|
|
supported names (aliases) and their dimensions in points. You are free to add |
1036
|
|
|
|
|
|
|
additional paper sizes to this file, if you wish. You might want to do this if |
1037
|
|
|
|
|
|
|
you frequently use a standard page size in rotated (Landscape) mode. See also |
1038
|
|
|
|
|
|
|
the C call in L. These names (aliases) are |
1039
|
|
|
|
|
|
|
also usable in other "box" calls, although useful only if the "box" is the same |
1040
|
|
|
|
|
|
|
size as the full media (Media Box), and you don't mind their starting at 0,0. |
1041
|
|
|
|
|
|
|
|
1042
|
|
|
|
|
|
|
=back |
1043
|
|
|
|
|
|
|
|
1044
|
|
|
|
|
|
|
=head3 Crop Box |
1045
|
|
|
|
|
|
|
|
1046
|
|
|
|
|
|
|
=over |
1047
|
|
|
|
|
|
|
|
1048
|
|
|
|
|
|
|
=item $pdf->cropbox($name) |
1049
|
|
|
|
|
|
|
|
1050
|
|
|
|
|
|
|
=item $pdf->cropbox($name, orient => 'orientation') |
1051
|
|
|
|
|
|
|
|
1052
|
|
|
|
|
|
|
=item $pdf->cropbox($w,$h) |
1053
|
|
|
|
|
|
|
|
1054
|
|
|
|
|
|
|
=item $pdf->cropbox($llx,$lly, $urx,$ury) |
1055
|
|
|
|
|
|
|
|
1056
|
|
|
|
|
|
|
=item ($llx,$lly, $urx,$ury) = $pdf->cropbox() |
1057
|
|
|
|
|
|
|
|
1058
|
|
|
|
|
|
|
Sets the global Crop Box (or page's Crop Box, if C<< $page-> >> instead). |
1059
|
|
|
|
|
|
|
This will define the media size to which the output will |
1060
|
|
|
|
|
|
|
later be I. Note that this does B itself output any crop marks |
1061
|
|
|
|
|
|
|
to guide cutting of the paper! PDF Readers should consider this to be the |
1062
|
|
|
|
|
|
|
I portion of the page, and anything found outside it I be clipped |
1063
|
|
|
|
|
|
|
(invisible). By default, it is equal to the Media Box, but may be defined to be |
1064
|
|
|
|
|
|
|
smaller, in the coordinate system set by the Media Box. A global setting will |
1065
|
|
|
|
|
|
|
be inherited by each page, but can be overridden on a per-page basis. |
1066
|
|
|
|
|
|
|
|
1067
|
|
|
|
|
|
|
A Reader or Printer may choose to discard any clipped (invisible) part of the |
1068
|
|
|
|
|
|
|
page, and show only the area I the Crop Box. For example, if your page |
1069
|
|
|
|
|
|
|
Media Box is A4 (0,0 to 595,842 Points), and your Crop Box is (100,100 to |
1070
|
|
|
|
|
|
|
495,742), a reader such as Adobe Acrobat Reader may show you a page 395 by |
1071
|
|
|
|
|
|
|
642 Points in size (i.e., just the visible area of your page). Other Readers |
1072
|
|
|
|
|
|
|
may show you the full media size (Media Box) and a 100 Point wide blank area |
1073
|
|
|
|
|
|
|
(in this example) around the visible content. |
1074
|
|
|
|
|
|
|
|
1075
|
|
|
|
|
|
|
If no arguments are given, the current Crop Box (global or page) coordinates |
1076
|
|
|
|
|
|
|
are returned instead. The former C (page only) function is |
1077
|
|
|
|
|
|
|
B and will likely be removed some time in the future. If a Crop Box |
1078
|
|
|
|
|
|
|
has not been defined, the Media Box coordinates (which always exist) will be |
1079
|
|
|
|
|
|
|
returned instead. In addition, |
1080
|
|
|
|
|
|
|
when I the Crop Box, the resulting coordinates are returned. This |
1081
|
|
|
|
|
|
|
permits you to specify the crop box by a name (alias) and get the dimensions |
1082
|
|
|
|
|
|
|
back, all in one call. |
1083
|
|
|
|
|
|
|
|
1084
|
|
|
|
|
|
|
Do not confuse the Crop Box with the C, which shows where printed |
1085
|
|
|
|
|
|
|
paper is expected to actually be I. Some PDF Readers may reduce the |
1086
|
|
|
|
|
|
|
visible "paper" background to the size of the crop box; others may simply omit |
1087
|
|
|
|
|
|
|
any content outside it. Either way, you would lose any trim or crop marks, |
1088
|
|
|
|
|
|
|
printer instructions, color alignment dots, or other content outside the Crop |
1089
|
|
|
|
|
|
|
Box. I would be limit printing to the area where a |
1090
|
|
|
|
|
|
|
printer I reliably put down ink, and leave white the edge areas where |
1091
|
|
|
|
|
|
|
paper-handling mechanisms prevent ink or toner from being applied. This would |
1092
|
|
|
|
|
|
|
keep you from accidentally putting valuable content in an area where a printer |
1093
|
|
|
|
|
|
|
will refuse to print, yet permit you to include a bleed area and space for |
1094
|
|
|
|
|
|
|
printer's marks and instructions. Needless to say, if your printer cannot print |
1095
|
|
|
|
|
|
|
to the very edge of the paper, you will need to trim (cut) the printed sheets |
1096
|
|
|
|
|
|
|
to get true bleeds. |
1097
|
|
|
|
|
|
|
|
1098
|
|
|
|
|
|
|
A global (PDF level) cropbox setting is inherited by each page, or can be |
1099
|
|
|
|
|
|
|
overridden by setting cropbox in the page. |
1100
|
|
|
|
|
|
|
As with C, only one crop box may be set at this (PDF) level. |
1101
|
|
|
|
|
|
|
As with C, a named media size may have an orientation (l or L) for |
1102
|
|
|
|
|
|
|
Landscape mode. |
1103
|
|
|
|
|
|
|
Note that the PDF level global Crop Box will be used I the page gets |
1104
|
|
|
|
|
|
|
its own Media Box. That is, the page's Crop Box inherits the global Crop Box, |
1105
|
|
|
|
|
|
|
not the page Media Box, even if the page has its own media size! If you set the |
1106
|
|
|
|
|
|
|
page's own Media Box, you should consider also explicitly setting the page |
1107
|
|
|
|
|
|
|
Crop Box (and other boxes). |
1108
|
|
|
|
|
|
|
|
1109
|
|
|
|
|
|
|
=back |
1110
|
|
|
|
|
|
|
|
1111
|
|
|
|
|
|
|
=head3 Bleed Box |
1112
|
|
|
|
|
|
|
|
1113
|
|
|
|
|
|
|
=over |
1114
|
|
|
|
|
|
|
|
1115
|
|
|
|
|
|
|
=item $pdf->bleedbox($name) |
1116
|
|
|
|
|
|
|
|
1117
|
|
|
|
|
|
|
=item $pdf->bleedbox($name, orient => 'orientation') |
1118
|
|
|
|
|
|
|
|
1119
|
|
|
|
|
|
|
=item $pdf->bleedbox($w,$h) |
1120
|
|
|
|
|
|
|
|
1121
|
|
|
|
|
|
|
=item $pdf->bleedbox($llx,$lly, $urx,$ury) |
1122
|
|
|
|
|
|
|
|
1123
|
|
|
|
|
|
|
=item ($llx,$lly, $urx,$ury) = $pdf->bleedbox() |
1124
|
|
|
|
|
|
|
|
1125
|
|
|
|
|
|
|
Sets the global Bleed Box (or page's Bleed Box, if C<< $page-> >> instead). |
1126
|
|
|
|
|
|
|
This is typically used in printing on paper, where you want |
1127
|
|
|
|
|
|
|
ink or color (such as thumb tabs) to be printed a bit beyond the final paper |
1128
|
|
|
|
|
|
|
size, to ensure that the cut paper I (the cut goes I the ink), |
1129
|
|
|
|
|
|
|
rather than accidentally leaving some white paper visible outside. Allow |
1130
|
|
|
|
|
|
|
enough "bleed" over the expected trim line to account for minor variations in |
1131
|
|
|
|
|
|
|
paper handling, folding, and cutting; to avoid showing white paper at the edge. |
1132
|
|
|
|
|
|
|
The Bleed Box is where I could actually extend to; the Trim Box is |
1133
|
|
|
|
|
|
|
normally within it, where the paper would actually be I. The default |
1134
|
|
|
|
|
|
|
value is equal to the Crop Box, but is often a bit smaller. The space between |
1135
|
|
|
|
|
|
|
the Bleed Box and the Crop Box is available for printer instructions, color |
1136
|
|
|
|
|
|
|
alignment dots, etc., while crop marks (trim guides) are at least partly within |
1137
|
|
|
|
|
|
|
the bleed area (and should be printed after content is printed). |
1138
|
|
|
|
|
|
|
|
1139
|
|
|
|
|
|
|
If no arguments are given, the current Bleed Box (global or page) coordinates |
1140
|
|
|
|
|
|
|
are returned instead. The former C (page only) function is |
1141
|
|
|
|
|
|
|
B and will likely be removed some time in the future. If a Bleed Box |
1142
|
|
|
|
|
|
|
has not been defined, the Crop Box coordinates (if defined) will be returned, |
1143
|
|
|
|
|
|
|
otherwise the Media Box coordinates (which always exist) will be returned. |
1144
|
|
|
|
|
|
|
In addition, when I the Bleed Box, the resulting coordinates are |
1145
|
|
|
|
|
|
|
returned. This permits you to specify the bleed box by a name (alias) and get |
1146
|
|
|
|
|
|
|
the dimensions back, all in one call. |
1147
|
|
|
|
|
|
|
|
1148
|
|
|
|
|
|
|
A global (PDF level) bleedbox setting is inherited by each page, or can be |
1149
|
|
|
|
|
|
|
overridden by setting bleedbox in the page. |
1150
|
|
|
|
|
|
|
As with C, only one bleed box may be set at this (PDF) level. |
1151
|
|
|
|
|
|
|
As with C, a named media size may have an orientation (l or L) for |
1152
|
|
|
|
|
|
|
Landscape mode. |
1153
|
|
|
|
|
|
|
Note that the PDF level global Bleed Box will be used I the page gets |
1154
|
|
|
|
|
|
|
its own Crop Box. That is, the page's Bleed Box inherits the global Bleed Box, |
1155
|
|
|
|
|
|
|
not the page Crop Box, even if the page has its own media size! If you set the |
1156
|
|
|
|
|
|
|
page's own Media Box or Crop Box, you should consider also explicitly setting |
1157
|
|
|
|
|
|
|
the page Bleed Box (and other boxes). |
1158
|
|
|
|
|
|
|
|
1159
|
|
|
|
|
|
|
=back |
1160
|
|
|
|
|
|
|
|
1161
|
|
|
|
|
|
|
=head3 Trim Box |
1162
|
|
|
|
|
|
|
|
1163
|
|
|
|
|
|
|
=over |
1164
|
|
|
|
|
|
|
|
1165
|
|
|
|
|
|
|
=item $pdf->trimbox($name) |
1166
|
|
|
|
|
|
|
|
1167
|
|
|
|
|
|
|
=item $pdf->trimbox($name, orient => 'orientation') |
1168
|
|
|
|
|
|
|
|
1169
|
|
|
|
|
|
|
=item $pdf->trimbox($w,$h) |
1170
|
|
|
|
|
|
|
|
1171
|
|
|
|
|
|
|
=item $pdf->trimbox($llx,$lly, $urx,$ury) |
1172
|
|
|
|
|
|
|
|
1173
|
|
|
|
|
|
|
=item ($llx,$lly, $urx,$ury) = $pdf->trimbox() |
1174
|
|
|
|
|
|
|
|
1175
|
|
|
|
|
|
|
Sets the global Trim Box (or page's Trim Box, if C<< $page-> >> instead). |
1176
|
|
|
|
|
|
|
This is supposed to be the actual dimensions of the |
1177
|
|
|
|
|
|
|
finished page (after trimming of the paper). In some production environments, |
1178
|
|
|
|
|
|
|
it is useful to have printer's instructions, cut marks, and so on outside of |
1179
|
|
|
|
|
|
|
the trim box. The default value is equal to Crop Box, but is often a bit |
1180
|
|
|
|
|
|
|
smaller than any Bleed Box, to allow the desired "bleed" effect. |
1181
|
|
|
|
|
|
|
|
1182
|
|
|
|
|
|
|
If no arguments are given, the current Trim Box (global or page) coordinates |
1183
|
|
|
|
|
|
|
are returned instead. The former C (page only) function is |
1184
|
|
|
|
|
|
|
B and will likely be removed some time in the future. If a Trim Box |
1185
|
|
|
|
|
|
|
has not been defined, the Crop Box coordinates (if defined) will be returned, |
1186
|
|
|
|
|
|
|
otherwise the Media Box coordinates (which always exist) will be returned. |
1187
|
|
|
|
|
|
|
In addition, when I the Trim Box, the resulting coordinates are |
1188
|
|
|
|
|
|
|
returned. This permits you to specify the trim box by a name (alias) and get |
1189
|
|
|
|
|
|
|
the dimensions back, all in one call. |
1190
|
|
|
|
|
|
|
|
1191
|
|
|
|
|
|
|
A global (PDF level) trimbox setting is inherited by each page, or can be |
1192
|
|
|
|
|
|
|
overridden by setting trimbox in the page. |
1193
|
|
|
|
|
|
|
As with C, only one trim box may be set at this (PDF) level. |
1194
|
|
|
|
|
|
|
As with C, a named media size may have an orientation (l or L) for |
1195
|
|
|
|
|
|
|
Landscape mode. |
1196
|
|
|
|
|
|
|
Note that the PDF level global Trim Box will be used I the page gets |
1197
|
|
|
|
|
|
|
its own Crop Box. That is, the page's Trim Box inherits the global Trim Box, |
1198
|
|
|
|
|
|
|
not the page Crop Box, even if the page has its own media size! If you set the |
1199
|
|
|
|
|
|
|
page's own Media Box or Crop Box, you should consider also explicitly setting |
1200
|
|
|
|
|
|
|
the page Trim Box (and other boxes). |
1201
|
|
|
|
|
|
|
|
1202
|
|
|
|
|
|
|
=back |
1203
|
|
|
|
|
|
|
|
1204
|
|
|
|
|
|
|
=head3 Art Box |
1205
|
|
|
|
|
|
|
|
1206
|
|
|
|
|
|
|
=over |
1207
|
|
|
|
|
|
|
|
1208
|
|
|
|
|
|
|
=item $pdf->artbox($name) |
1209
|
|
|
|
|
|
|
|
1210
|
|
|
|
|
|
|
=item $pdf->artbox($name, orient => 'orientation') |
1211
|
|
|
|
|
|
|
|
1212
|
|
|
|
|
|
|
=item $pdf->artbox($w,$h) |
1213
|
|
|
|
|
|
|
|
1214
|
|
|
|
|
|
|
=item $pdf->artbox($llx,$lly, $urx,$ury) |
1215
|
|
|
|
|
|
|
|
1216
|
|
|
|
|
|
|
=item ($llx,$lly, $urx,$ury) = $pdf->artbox() |
1217
|
|
|
|
|
|
|
|
1218
|
|
|
|
|
|
|
Sets the global Art Box (or page's Art Box, if C<< $page-> >> instead). |
1219
|
|
|
|
|
|
|
This is supposed to define "the extent of the page's |
1220
|
|
|
|
|
|
|
I content (including [margins])". It might exclude some content, |
1221
|
|
|
|
|
|
|
such as Headlines or headings. Any binding or punched-holes margin would |
1222
|
|
|
|
|
|
|
typically be outside of the Art Box, as would be page numbers and running |
1223
|
|
|
|
|
|
|
headers and footers. The default value is equal to the Crop Box, although |
1224
|
|
|
|
|
|
|
normally it would be no larger than any Trim Box. The Art Box may often be |
1225
|
|
|
|
|
|
|
used for defining "important" content (e.g., I advertisements) that |
1226
|
|
|
|
|
|
|
may or may not be brought over to another page (e.g., N-up printing). |
1227
|
|
|
|
|
|
|
|
1228
|
|
|
|
|
|
|
If no arguments are given, the current Art Box (global or page) coordinates |
1229
|
|
|
|
|
|
|
are returned instead. The former C (page only) function is |
1230
|
|
|
|
|
|
|
B and will likely be removed some time in the future. If an Art Box |
1231
|
|
|
|
|
|
|
has not been defined, the Crop Box coordinates (if defined) will be returned, |
1232
|
|
|
|
|
|
|
otherwise the Media Box coordinates (which always exist) will be returned. |
1233
|
|
|
|
|
|
|
In addition, when I the Art Box, the resulting coordinates are |
1234
|
|
|
|
|
|
|
returned. This permits you to specify the art box by a name (alias) and get |
1235
|
|
|
|
|
|
|
the dimensions back, all in one call. |
1236
|
|
|
|
|
|
|
|
1237
|
|
|
|
|
|
|
A global (PDF level) artbox setting is inherited by each page, or can be |
1238
|
|
|
|
|
|
|
overridden by setting artbox in the page. |
1239
|
|
|
|
|
|
|
As with C, only one art box may be set at this (PDF) level. |
1240
|
|
|
|
|
|
|
As with C, a named media size may have an orientation (l or L) for |
1241
|
|
|
|
|
|
|
Landscape mode. |
1242
|
|
|
|
|
|
|
Note that the PDF level global Art Box will be used I the page gets |
1243
|
|
|
|
|
|
|
its own Crop Box. That is, the page's Art Box inherits the global Art Box, |
1244
|
|
|
|
|
|
|
not the page Crop Box, even if the page has its own media size! If you set the |
1245
|
|
|
|
|
|
|
page's own Media Box or Crop Box, you should consider also explicitly setting |
1246
|
|
|
|
|
|
|
the page Art Box (and other boxes). |
1247
|
|
|
|
|
|
|
|
1248
|
|
|
|
|
|
|
=back |
1249
|
|
|
|
|
|
|
|
1250
|
|
|
|
|
|
|
=head3 Suggested Box Usage |
1251
|
|
|
|
|
|
|
|
1252
|
|
|
|
|
|
|
See C for an example of using boxes. |
1253
|
|
|
|
|
|
|
|
1254
|
|
|
|
|
|
|
How you define your boxes (or let them default) is up to you, depending on |
1255
|
|
|
|
|
|
|
whether you're duplex printing US Letter or A4 on your laser printer, to be |
1256
|
|
|
|
|
|
|
spiral bound on the bind margin, or engaging a professional printer. In the |
1257
|
|
|
|
|
|
|
latter case, discuss in advance with the print firm what capabilities (and |
1258
|
|
|
|
|
|
|
limitations) they have |
1259
|
|
|
|
|
|
|
and what information they need from a PDF file. For instance, they may not want |
1260
|
|
|
|
|
|
|
a Crop Box defined, and may call for very specific box sizes. For large press |
1261
|
|
|
|
|
|
|
runs, they may print multiple pages (N-up) duplexed on large web roll |
1262
|
|
|
|
|
|
|
"signatures", which are then intricately folded and guillotined (trimmed) and |
1263
|
|
|
|
|
|
|
bound together into books or magazines. You would usually just supply a PDF |
1264
|
|
|
|
|
|
|
with all the pages; they would take care of the signature layout (which |
1265
|
|
|
|
|
|
|
includes offsets and 180 degree rotations). |
1266
|
|
|
|
|
|
|
|
1267
|
|
|
|
|
|
|
(As an aside, don't count on a printer having |
1268
|
|
|
|
|
|
|
any particular font available, so be sure to ask. Usually they will want you |
1269
|
|
|
|
|
|
|
to embed all fonts used, but ask first, and double-check before handing over |
1270
|
|
|
|
|
|
|
the print job! TTF/OTF fonts (C) are embedded by default, but other |
1271
|
|
|
|
|
|
|
fonts (core, ps, bdf, cjk) are not! A printer I have a core font |
1272
|
|
|
|
|
|
|
collection, but they are free to substitute a "workalike" font for any given |
1273
|
|
|
|
|
|
|
core font, and the results may not match what you saw on your PC!) |
1274
|
|
|
|
|
|
|
|
1275
|
|
|
|
|
|
|
On the assumption that you're using a single sheet (US Letter or A4) laser or |
1276
|
|
|
|
|
|
|
inkjet printer, are you planning to trim each sheet down to a smaller final |
1277
|
|
|
|
|
|
|
size? If so, you can do true bleeds by defining a Trim Box and a slightly |
1278
|
|
|
|
|
|
|
larger Bleed Box. You would print bleeds (all the way to the finished edge) |
1279
|
|
|
|
|
|
|
out to the Bleed Box, but nothing is enforced about the Bleed Box. At the other |
1280
|
|
|
|
|
|
|
end of the spectrum, you would define the Media |
1281
|
|
|
|
|
|
|
Box to be the physical paper size being printed on. Most printers reserve a |
1282
|
|
|
|
|
|
|
little space on the sides (and possibly top and bottom) for paper handling, so |
1283
|
|
|
|
|
|
|
it is often good to define your Crop Box as the printable area. Remember that |
1284
|
|
|
|
|
|
|
the Media Box sets the coordinate system used, so you still need to avoid |
1285
|
|
|
|
|
|
|
going outside the Crop Box with content (most readers and printers will not |
1286
|
|
|
|
|
|
|
show any ink outside of the Crop Box). Whether or not you define a Crop Box, |
1287
|
|
|
|
|
|
|
you're going to almost always end up with white paper on at least the sides. |
1288
|
|
|
|
|
|
|
|
1289
|
|
|
|
|
|
|
For small in-house jobs, you probably won't need color alignment dots and other |
1290
|
|
|
|
|
|
|
such professional instructions and information between the Bleed Box and the |
1291
|
|
|
|
|
|
|
Crop Box, but crop marks for trimming (if used) should go just outside the Trim |
1292
|
|
|
|
|
|
|
Box (partly or wholly within the Bleed Box), and |
1293
|
|
|
|
|
|
|
be drawn I all content. If you're I trimming the paper, don't try |
1294
|
|
|
|
|
|
|
to do any bleed effects (including solid background color pages/covers), as |
1295
|
|
|
|
|
|
|
you will usually have a white edge around the |
1296
|
|
|
|
|
|
|
sheet anyway. Don't count on a PDF document I being physically printed, |
1297
|
|
|
|
|
|
|
and not just displayed (where you can do things like bleed all the way to the |
1298
|
|
|
|
|
|
|
media edge). Finally, for single sheet printing, an Art Box is |
1299
|
|
|
|
|
|
|
probably unnecessary, but if you're combining pages into N-up prints, or doing |
1300
|
|
|
|
|
|
|
other manipulations, it may be useful. |
1301
|
|
|
|
|
|
|
|
1302
|
|
|
|
|
|
|
=head3 Box Inheritance |
1303
|
|
|
|
|
|
|
|
1304
|
|
|
|
|
|
|
What Media, Crop, Bleed, Trim, and Art Boxes a page gets can be a little |
1305
|
|
|
|
|
|
|
complicated. Note that usually, only the Media and Crop Boxes will have a |
1306
|
|
|
|
|
|
|
clear visual effect. The visual effect of the other boxes (if any) may be |
1307
|
|
|
|
|
|
|
very subtle. |
1308
|
|
|
|
|
|
|
|
1309
|
|
|
|
|
|
|
First, everything is set at the global (PDF) level. The Media Box is always |
1310
|
|
|
|
|
|
|
defined, and defaults to US Letter (8.5 inches wide by 11 inches high). The |
1311
|
|
|
|
|
|
|
global Crop Box inherits the Media Box, unless explicitly defined. The Bleed, |
1312
|
|
|
|
|
|
|
Trim, and Art Boxes inherit the Crop Box, unless explicitly defined. A global |
1313
|
|
|
|
|
|
|
box should only be defined once, as the last one defined is the one that will |
1314
|
|
|
|
|
|
|
be written to the PDF! |
1315
|
|
|
|
|
|
|
|
1316
|
|
|
|
|
|
|
Second, a page inherits the global boxes, for its initial settings. You may |
1317
|
|
|
|
|
|
|
call any of the box set methods (C, C, etc.) to explicitly |
1318
|
|
|
|
|
|
|
set (override) any box for I page. Note that setting a new Media Box for |
1319
|
|
|
|
|
|
|
the page does B reset the page's Crop Box -- it still uses whatever it |
1320
|
|
|
|
|
|
|
inherited from the global Crop Box. You would need to explicitly set the page's |
1321
|
|
|
|
|
|
|
Crop Box if you want a different setting. Likewise, the page's Bleed, Trim, and |
1322
|
|
|
|
|
|
|
Art Boxes will not be reset by a new page Crop Box -- they will still inherit |
1323
|
|
|
|
|
|
|
from the global (PDF) settings. |
1324
|
|
|
|
|
|
|
|
1325
|
|
|
|
|
|
|
Third, the page Media Box (the one actually used for output pages), clips or |
1326
|
|
|
|
|
|
|
limits all the other boxes to extend no larger than its size. For example, if |
1327
|
|
|
|
|
|
|
the Media Box is US Letter, and you set a Crop Box of A4 size, the smaller of |
1328
|
|
|
|
|
|
|
the two heights (11 inches) would be effective, and the smaller of the two |
1329
|
|
|
|
|
|
|
widths (8.26 inches, 595 Points) would be effective. |
1330
|
|
|
|
|
|
|
The I dimensions of a box are returned on query (get), not the |
1331
|
|
|
|
|
|
|
I dimensions clipped by the Media Box. |
1332
|
|
|
|
|
|
|
|
1333
|
|
|
|
|
|
|
=head2 FONT METHODS |
1334
|
|
|
|
|
|
|
|
1335
|
|
|
|
|
|
|
=head3 Core Fonts |
1336
|
|
|
|
|
|
|
|
1337
|
|
|
|
|
|
|
Core fonts are limited to single byte encodings. You cannot use UTF-8 or other |
1338
|
|
|
|
|
|
|
multibyte encodings with core fonts. The default encoding for the core fonts is |
1339
|
|
|
|
|
|
|
WinAnsiEncoding (roughly the CP-1252 superset of ISO-8859-1). See the |
1340
|
|
|
|
|
|
|
C option below to change this encoding. |
1341
|
|
|
|
|
|
|
See L method for information on |
1342
|
|
|
|
|
|
|
accessing more than 256 glyphs in a font, using planes, I
|
1343
|
|
|
|
|
|
|
guarantee that future changes to font files will permit consistent results>. |
1344
|
|
|
|
|
|
|
|
1345
|
|
|
|
|
|
|
Note that core fonts use fixed lists of expected glyphs, along with metrics |
1346
|
|
|
|
|
|
|
such as their widths. This may not exactly match up with whatever local font |
1347
|
|
|
|
|
|
|
file is used by the PDF reader. It's usually pretty close, but many cases have |
1348
|
|
|
|
|
|
|
been found where the list of glyphs is different between the core fonts and |
1349
|
|
|
|
|
|
|
various local font files, so be aware of this. |
1350
|
|
|
|
|
|
|
|
1351
|
|
|
|
|
|
|
To allow UTF-8 text and extended glyph counts, you should |
1352
|
|
|
|
|
|
|
consider replacing your use of core fonts with TrueType (.ttf) and OpenType |
1353
|
|
|
|
|
|
|
(.otf) fonts. There are tools, such as I, which can do a fairly good |
1354
|
|
|
|
|
|
|
(though, not perfect) job of converting a Type1 font library to OTF. |
1355
|
|
|
|
|
|
|
|
1356
|
|
|
|
|
|
|
B |
1357
|
|
|
|
|
|
|
|
1358
|
|
|
|
|
|
|
$font1 = $pdf->corefont('Times-Roman', encode => 'latin2'); |
1359
|
|
|
|
|
|
|
$font2 = $pdf->corefont('Times-Bold'); |
1360
|
|
|
|
|
|
|
$font3 = $pdf->corefont('Helvetica'); |
1361
|
|
|
|
|
|
|
$font4 = $pdf->corefont('ZapfDingbats'); |
1362
|
|
|
|
|
|
|
|
1363
|
|
|
|
|
|
|
Valid %options are: |
1364
|
|
|
|
|
|
|
|
1365
|
|
|
|
|
|
|
=over |
1366
|
|
|
|
|
|
|
|
1367
|
|
|
|
|
|
|
=item encode |
1368
|
|
|
|
|
|
|
|
1369
|
|
|
|
|
|
|
Changes the encoding of the font from its default. Notice that the encoding |
1370
|
|
|
|
|
|
|
(I the entire font's glyph list) is shown in a PDF object (record), listing |
1371
|
|
|
|
|
|
|
256 glyphs associated with this encoding (I that are available in this |
1372
|
|
|
|
|
|
|
font). |
1373
|
|
|
|
|
|
|
|
1374
|
|
|
|
|
|
|
=item dokern |
1375
|
|
|
|
|
|
|
|
1376
|
|
|
|
|
|
|
Enables kerning if data is available. |
1377
|
|
|
|
|
|
|
|
1378
|
|
|
|
|
|
|
=back |
1379
|
|
|
|
|
|
|
|
1380
|
|
|
|
|
|
|
B |
1381
|
|
|
|
|
|
|
|
1382
|
|
|
|
|
|
|
Even though these are called "core" fonts, they are I shipped |
1383
|
|
|
|
|
|
|
with PDF::Builder, but are expected to be found on the machine with the PDF |
1384
|
|
|
|
|
|
|
reader. Most core fonts are installed with a PDF reader, and thus are not |
1385
|
|
|
|
|
|
|
coordinated with PDF::Builder. PDF::Builder I ship with core font |
1386
|
|
|
|
|
|
|
I files (width, glyph names, etc.), but these cannot be guaranteed to |
1387
|
|
|
|
|
|
|
be in sync with what the PDF reader has installed! |
1388
|
|
|
|
|
|
|
|
1389
|
|
|
|
|
|
|
There are some 14 core fonts (regular, italic, bold, and bold-italic for |
1390
|
|
|
|
|
|
|
Times [serif], Helvetica [sans serif], Courier [fixed pitch]; plus two symbol |
1391
|
|
|
|
|
|
|
fonts) that are supposed to be available on any PDF reader, B
|
1392
|
|
|
|
|
|
|
fonts with very similar metrics are often substituted.> You should I count |
1393
|
|
|
|
|
|
|
on any of the 15 Windows core fonts (Bank Gothic, Georgia, Trebuchet, Verdana, |
1394
|
|
|
|
|
|
|
and two more symbol fonts) being present, especially on Linux, Mac, or other |
1395
|
|
|
|
|
|
|
non-Windows platforms. Be aware if you are producing PDFs to be read on a |
1396
|
|
|
|
|
|
|
variety of different systems! |
1397
|
|
|
|
|
|
|
|
1398
|
|
|
|
|
|
|
If you want to ensure the widest portability for a PDF document you produce, |
1399
|
|
|
|
|
|
|
you should consider using TTF fonts (instead of core fonts) and embedding them |
1400
|
|
|
|
|
|
|
in the document. This ensures that there will be no substitutions, that all |
1401
|
|
|
|
|
|
|
metrics are known and match the glyphs, UTF-8 encoding can be used, and |
1402
|
|
|
|
|
|
|
that the glyphs I be available on the reader's machine. At least on |
1403
|
|
|
|
|
|
|
Windows platforms, most of the fonts are TTF anyway, which are used behind the |
1404
|
|
|
|
|
|
|
scenes for "core" fonts, while missing most of the capabilities of TTF (now |
1405
|
|
|
|
|
|
|
or possibly later in PDF::Builder) such as embedding, ligatures, UTF-8, etc. |
1406
|
|
|
|
|
|
|
The downside is, obviously, that the resulting PDF file will be larger because |
1407
|
|
|
|
|
|
|
it includes the font(s). There I also be copyright or licensing issues |
1408
|
|
|
|
|
|
|
with the redistribution of font files in this manner (you might want to check, |
1409
|
|
|
|
|
|
|
before widely distributing a PDF document with embedded fonts, although many |
1410
|
|
|
|
|
|
|
I permit the part of the font used, to be embedded.). |
1411
|
|
|
|
|
|
|
|
1412
|
|
|
|
|
|
|
See also L. |
1413
|
|
|
|
|
|
|
|
1414
|
|
|
|
|
|
|
=head3 PS Fonts |
1415
|
|
|
|
|
|
|
|
1416
|
|
|
|
|
|
|
PS (T1) fonts are limited to single byte encodings. You cannot use UTF-8 or |
1417
|
|
|
|
|
|
|
other multibyte encodings with T1 fonts. |
1418
|
|
|
|
|
|
|
The default encoding for the T1 fonts is |
1419
|
|
|
|
|
|
|
WinAnsiEncoding (roughly the CP-1252 superset of ISO-8859-1). See the |
1420
|
|
|
|
|
|
|
C option below to change this encoding. |
1421
|
|
|
|
|
|
|
See L method for information on |
1422
|
|
|
|
|
|
|
accessing more than 256 glyphs in a font, using planes, I
|
1423
|
|
|
|
|
|
|
guarantee that future changes to font files will permit consistent results>. |
1424
|
|
|
|
|
|
|
B many Type1 fonts are limited to 256 glyphs, but some are available |
1425
|
|
|
|
|
|
|
with more than 256 glyphs. Still, a maximum of 256 at a time are usable. |
1426
|
|
|
|
|
|
|
|
1427
|
|
|
|
|
|
|
C accepts both ASCII (.pfa) and binary (.pfb) Type1 glyph files. |
1428
|
|
|
|
|
|
|
Font metrics can be supplied in either ASCII (.afm) or binary (.pfm) format, |
1429
|
|
|
|
|
|
|
as can be seen in the examples given below. It is possible to use .pfa with .pfm |
1430
|
|
|
|
|
|
|
and .pfb with .afm if that's what's available. The ASCII and binary files have |
1431
|
|
|
|
|
|
|
the same content, just in different formats. |
1432
|
|
|
|
|
|
|
|
1433
|
|
|
|
|
|
|
To allow UTF-8 text and extended glyph counts in one font, you should |
1434
|
|
|
|
|
|
|
consider replacing your use of Type1 fonts with TrueType (.ttf) and OpenType |
1435
|
|
|
|
|
|
|
(.otf) fonts. There are tools, such as I, which can do a fairly good |
1436
|
|
|
|
|
|
|
(though, not perfect) job of converting your font library to OTF. |
1437
|
|
|
|
|
|
|
|
1438
|
|
|
|
|
|
|
B |
1439
|
|
|
|
|
|
|
|
1440
|
|
|
|
|
|
|
$font1 = $pdf->psfont('Times-Book.pfa', afmfile => 'Times-Book.afm'); |
1441
|
|
|
|
|
|
|
$font2 = $pdf->psfont('/fonts/Synest-FB.pfb', pfmfile => '/fonts/Synest-FB.pfm'); |
1442
|
|
|
|
|
|
|
|
1443
|
|
|
|
|
|
|
Valid %options are: |
1444
|
|
|
|
|
|
|
|
1445
|
|
|
|
|
|
|
=over |
1446
|
|
|
|
|
|
|
|
1447
|
|
|
|
|
|
|
=item encode |
1448
|
|
|
|
|
|
|
|
1449
|
|
|
|
|
|
|
Changes the encoding of the font from its default. Notice that the encoding |
1450
|
|
|
|
|
|
|
(I the entire font's glyph list) is shown in a PDF object (record), listing |
1451
|
|
|
|
|
|
|
256 glyphs associated with this encoding (I that are available in this |
1452
|
|
|
|
|
|
|
font). |
1453
|
|
|
|
|
|
|
|
1454
|
|
|
|
|
|
|
=item afmfile |
1455
|
|
|
|
|
|
|
|
1456
|
|
|
|
|
|
|
Specifies the location of the I font metrics file (.afm). It may be used |
1457
|
|
|
|
|
|
|
with either an ASCII (.pfa) or binary (.pfb) glyph file. |
1458
|
|
|
|
|
|
|
|
1459
|
|
|
|
|
|
|
=item pfmfile |
1460
|
|
|
|
|
|
|
|
1461
|
|
|
|
|
|
|
Specifies the location of the I font metrics file (.pfm). It may be used |
1462
|
|
|
|
|
|
|
with either an ASCII (.pfa) or binary (.pfb) glyph file. |
1463
|
|
|
|
|
|
|
|
1464
|
|
|
|
|
|
|
=item dokern |
1465
|
|
|
|
|
|
|
|
1466
|
|
|
|
|
|
|
Enables kerning if data is available. |
1467
|
|
|
|
|
|
|
|
1468
|
|
|
|
|
|
|
=back |
1469
|
|
|
|
|
|
|
|
1470
|
|
|
|
|
|
|
B these T1 (Type1) fonts are I shipped with PDF::Builder, but are |
1471
|
|
|
|
|
|
|
expected to be found on the machine with the PDF reader. Most PDF readers do |
1472
|
|
|
|
|
|
|
not install T1 fonts, and it is up to the user of the PDF reader to install |
1473
|
|
|
|
|
|
|
the needed fonts. Unlike TrueType fonts, PS (T1) fonts are not embedded in the |
1474
|
|
|
|
|
|
|
PDF, and must be supplied on the Reader end. |
1475
|
|
|
|
|
|
|
|
1476
|
|
|
|
|
|
|
See also L. |
1477
|
|
|
|
|
|
|
|
1478
|
|
|
|
|
|
|
=head3 TrueType Fonts |
1479
|
|
|
|
|
|
|
|
1480
|
|
|
|
|
|
|
B BaseEncoding is I set by default for TrueType fonts, so B
|
1481
|
|
|
|
|
|
|
in the PDF isn't searchable> (by the PDF reader) unless a ToUnicode CMap is |
1482
|
|
|
|
|
|
|
included. A ToUnicode CMap I included by default (unicodemap set to 1) by |
1483
|
|
|
|
|
|
|
PDF::Builder, but allows it to be disabled (for performance and file size |
1484
|
|
|
|
|
|
|
reasons) by setting unicodemap to 0. This will produce non-searchable text, |
1485
|
|
|
|
|
|
|
which, besides being annoying to users, may prevent screen |
1486
|
|
|
|
|
|
|
readers and other aids to disabled users from working correctly! |
1487
|
|
|
|
|
|
|
|
1488
|
|
|
|
|
|
|
B |
1489
|
|
|
|
|
|
|
|
1490
|
|
|
|
|
|
|
$font1 = $pdf->ttfont('Times.ttf'); |
1491
|
|
|
|
|
|
|
$font2 = $pdf->ttfont('Georgia.otf'); |
1492
|
|
|
|
|
|
|
|
1493
|
|
|
|
|
|
|
Valid %options are: |
1494
|
|
|
|
|
|
|
|
1495
|
|
|
|
|
|
|
=over |
1496
|
|
|
|
|
|
|
|
1497
|
|
|
|
|
|
|
=item encode |
1498
|
|
|
|
|
|
|
|
1499
|
|
|
|
|
|
|
Changes the encoding of the font from its default (WinAnsiEncoding). |
1500
|
|
|
|
|
|
|
|
1501
|
|
|
|
|
|
|
Note that for a single byte encoding (e.g., 'latin1'), you are limited to 256 |
1502
|
|
|
|
|
|
|
characters defined for that encoding. 'automap' does not work with TrueType. |
1503
|
|
|
|
|
|
|
If you want more characters than that, use 'utf8' encoding with a UTF-8 |
1504
|
|
|
|
|
|
|
encoded text string. |
1505
|
|
|
|
|
|
|
|
1506
|
|
|
|
|
|
|
=item isocmap |
1507
|
|
|
|
|
|
|
|
1508
|
|
|
|
|
|
|
Use the ISO Unicode Map instead of the default MS Unicode Map. |
1509
|
|
|
|
|
|
|
|
1510
|
|
|
|
|
|
|
=item unicodemap |
1511
|
|
|
|
|
|
|
|
1512
|
|
|
|
|
|
|
If 1 (default), output ToUnicode CMap to permit text searches and screen |
1513
|
|
|
|
|
|
|
readers. Set to 0 to save space by I including the ToUnicode CMap, but |
1514
|
|
|
|
|
|
|
text searching and screen reading will not be possible. |
1515
|
|
|
|
|
|
|
|
1516
|
|
|
|
|
|
|
=item dokern |
1517
|
|
|
|
|
|
|
|
1518
|
|
|
|
|
|
|
Enables kerning if data is available. |
1519
|
|
|
|
|
|
|
|
1520
|
|
|
|
|
|
|
=item noembed |
1521
|
|
|
|
|
|
|
|
1522
|
|
|
|
|
|
|
Disables embedding of the font file. B
|
1523
|
|
|
|
|
|
|
as the glyphs provided on the PDF reader machine may not match what was used on |
1524
|
|
|
|
|
|
|
the PDF writer machine (the one running PDF::Builder)!> If you know I |
1525
|
|
|
|
|
|
|
that all PDF readers will be using the same TTF or OTF file you're using with |
1526
|
|
|
|
|
|
|
PDF::Builder; not embedding the font may be acceptable, in return for a smaller |
1527
|
|
|
|
|
|
|
PDF file size. Note that the Reader needs to know where to find the font file |
1528
|
|
|
|
|
|
|
-- it can't be in any random place, but typically needs to be listed in a path |
1529
|
|
|
|
|
|
|
that the Reader follows. Otherwise, it will be unable to render the text! |
1530
|
|
|
|
|
|
|
|
1531
|
|
|
|
|
|
|
The only value for the C flag currently checked for is B<1>, which |
1532
|
|
|
|
|
|
|
means to I embed the font file in the PDF. Any other value currently |
1533
|
|
|
|
|
|
|
results in the font file being embedded (by B), although in the future, |
1534
|
|
|
|
|
|
|
other values might be given significance (such as checking permission bits). |
1535
|
|
|
|
|
|
|
|
1536
|
|
|
|
|
|
|
Some additional comments on embedding font file(s) into the PDF: besides |
1537
|
|
|
|
|
|
|
substantially increasing the size of the PDF (even if the font is subsetted, |
1538
|
|
|
|
|
|
|
by default), PDF::Builder does not check the font file for any flags indicating |
1539
|
|
|
|
|
|
|
font licensing issues and limitations on use. A font foundry may not permit |
1540
|
|
|
|
|
|
|
embedding at all, may permit a subset of the font to be embedded, may permit a |
1541
|
|
|
|
|
|
|
full font to be embedded, and may specify what can be done with an embedded |
1542
|
|
|
|
|
|
|
font (e.g., may or may not be extracted for further use beyond displaying this |
1543
|
|
|
|
|
|
|
one PDF). When you choose to use (and embed) a font, you should be aware of any |
1544
|
|
|
|
|
|
|
such licensing issues. |
1545
|
|
|
|
|
|
|
|
1546
|
|
|
|
|
|
|
=item nosubset |
1547
|
|
|
|
|
|
|
|
1548
|
|
|
|
|
|
|
Disables subsetting of a TTF/OTF font, when embedded. By default, only the |
1549
|
|
|
|
|
|
|
glyphs used by a document are included in the file, and I the entire font. |
1550
|
|
|
|
|
|
|
This can result in a tremendous savings in PDF file size. If you intend to |
1551
|
|
|
|
|
|
|
allow the PDF to be edited by users, not having the entire font glyph set |
1552
|
|
|
|
|
|
|
available may cause problems, so be aware of that (and consider using |
1553
|
|
|
|
|
|
|
C<< nosubset => 1 >>. Setting this flag to any value results in the entire |
1554
|
|
|
|
|
|
|
font glyph set being embedded in the file. It might be a good idea to use only |
1555
|
|
|
|
|
|
|
the value B<1>, in case other values are assigned roles in the future. |
1556
|
|
|
|
|
|
|
|
1557
|
|
|
|
|
|
|
=item debug |
1558
|
|
|
|
|
|
|
|
1559
|
|
|
|
|
|
|
If set to 1 (default is 0), diagnostic information is output about the CMap |
1560
|
|
|
|
|
|
|
processing. |
1561
|
|
|
|
|
|
|
|
1562
|
|
|
|
|
|
|
=item usecmf |
1563
|
|
|
|
|
|
|
|
1564
|
|
|
|
|
|
|
If set to 1 (default is 0), the first priority is to make use of one of the |
1565
|
|
|
|
|
|
|
four C<.cmap> files for CJK fonts. This is the I way of processing TTF |
1566
|
|
|
|
|
|
|
files. If, after all is said and done, a working I CMap hasn't been |
1567
|
|
|
|
|
|
|
found (for usecmf=>0), C will fall back to using a C<.cmap> file |
1568
|
|
|
|
|
|
|
if possible. |
1569
|
|
|
|
|
|
|
|
1570
|
|
|
|
|
|
|
=item cmaps |
1571
|
|
|
|
|
|
|
|
1572
|
|
|
|
|
|
|
This flag may be set to a string listing the Platform/Encoding pairs to look |
1573
|
|
|
|
|
|
|
for of any internal CMaps in the font file, in the desired order (highest |
1574
|
|
|
|
|
|
|
priority first). If one list (comma and/or space-separated pairs) is given, it |
1575
|
|
|
|
|
|
|
is used for both Windows and non-Windows platforms (on which PDF::Builder is |
1576
|
|
|
|
|
|
|
running, I the PDF reader's). Two lists, separated by a semicolon ; may be |
1577
|
|
|
|
|
|
|
given, with the first being used for a Windows platform and the second for |
1578
|
|
|
|
|
|
|
non-Windows. The default list is C<0/6 3/10 0/4 3/1 0/3; 0/6 0/4 3/10 0/3 3/1>. |
1579
|
|
|
|
|
|
|
Finally, instead of a P/E list, a string C may be given to tell it to |
1580
|
|
|
|
|
|
|
simply call the Font::TTF C method to find a (preferably Windows) |
1581
|
|
|
|
|
|
|
internal CMap. C set to 'find_ms' would emulate the I way of |
1582
|
|
|
|
|
|
|
looking for CMaps. Symbol fonts (3/0) always use find_ms(), and the new default |
1583
|
|
|
|
|
|
|
lookup is (if C<.cmap> isn't used, see C) to try to get a match with |
1584
|
|
|
|
|
|
|
the default list for the appropriate OS. If none can be found, find_ms() is |
1585
|
|
|
|
|
|
|
tried, and as last resort use the C<.cmap> (if available), even if C |
1586
|
|
|
|
|
|
|
is not 1. |
1587
|
|
|
|
|
|
|
|
1588
|
|
|
|
|
|
|
=back |
1589
|
|
|
|
|
|
|
|
1590
|
|
|
|
|
|
|
=head3 CJK Fonts |
1591
|
|
|
|
|
|
|
|
1592
|
|
|
|
|
|
|
B |
1593
|
|
|
|
|
|
|
|
1594
|
|
|
|
|
|
|
$font = $pdf->cjkfont('korean'); |
1595
|
|
|
|
|
|
|
$font = $pdf->cjkfont('traditional'); |
1596
|
|
|
|
|
|
|
|
1597
|
|
|
|
|
|
|
Valid %options are: |
1598
|
|
|
|
|
|
|
|
1599
|
|
|
|
|
|
|
=over |
1600
|
|
|
|
|
|
|
|
1601
|
|
|
|
|
|
|
=item encode |
1602
|
|
|
|
|
|
|
|
1603
|
|
|
|
|
|
|
Changes the encoding of the font from its default. |
1604
|
|
|
|
|
|
|
|
1605
|
|
|
|
|
|
|
=back |
1606
|
|
|
|
|
|
|
|
1607
|
|
|
|
|
|
|
B Unlike C, the font file is I embedded in the output |
1608
|
|
|
|
|
|
|
PDF file. This is |
1609
|
|
|
|
|
|
|
evidently behavior left over from the early days of CJK fonts, where the |
1610
|
|
|
|
|
|
|
C and C were always external files, rather than internal tables. |
1611
|
|
|
|
|
|
|
If you need a CJK-using PDF file to embed the font, for portability, you can |
1612
|
|
|
|
|
|
|
create a PDF using C, and then use an external utility (e.g., |
1613
|
|
|
|
|
|
|
C) to embed the font in the PDF. It may also be possible to use |
1614
|
|
|
|
|
|
|
C instead, to produce the PDF, provided you can deduce the correct |
1615
|
|
|
|
|
|
|
font file name from examining the PDF file (e.g., on my Windows system, the |
1616
|
|
|
|
|
|
|
"Ming" font would be C<< $font = $pdf->ttfont("C:/Program Files/Adobe/Acrobat DC/Resource/CIDFont/AdobeMingStd-Light.otf") >>. |
1617
|
|
|
|
|
|
|
Of course, the font file used would have to be C<.ttf> or C<.otf>. |
1618
|
|
|
|
|
|
|
It may act a little differently than C (due a a different Cmap), but |
1619
|
|
|
|
|
|
|
you I be able to embed the font file into the PDF. |
1620
|
|
|
|
|
|
|
|
1621
|
|
|
|
|
|
|
See also L |
1622
|
|
|
|
|
|
|
|
1623
|
|
|
|
|
|
|
=head3 Synthetic Fonts |
1624
|
|
|
|
|
|
|
|
1625
|
|
|
|
|
|
|
B BaseEncoding is I set by default for these fonts, so text |
1626
|
|
|
|
|
|
|
in the PDF isn't searchable (by the PDF reader) unless a ToUnicode CMap is |
1627
|
|
|
|
|
|
|
included. A ToUnicode CMap I included by default (unicodemap set to 1) by |
1628
|
|
|
|
|
|
|
PDF::Builder, but allows it to be disabled (for performance and file size |
1629
|
|
|
|
|
|
|
reasons) by setting unicodemap to 0. This will produce non-searchable text, |
1630
|
|
|
|
|
|
|
which, besides being annoying to users, may prevent screen |
1631
|
|
|
|
|
|
|
readers and other aids to disabled users from working correctly! |
1632
|
|
|
|
|
|
|
|
1633
|
|
|
|
|
|
|
B |
1634
|
|
|
|
|
|
|
|
1635
|
|
|
|
|
|
|
$cf = $pdf->corefont('Times-Roman', encode => 'latin1'); |
1636
|
|
|
|
|
|
|
$sf = $pdf->synfont($cf, condense => 0.85); # compressed 85% |
1637
|
|
|
|
|
|
|
$sfb = $pdf->synfont($cf, bold => 1); # embolden by 10em |
1638
|
|
|
|
|
|
|
$sfi = $pdf->synfont($cf, oblique => -12); # italic at -12 degrees |
1639
|
|
|
|
|
|
|
|
1640
|
|
|
|
|
|
|
Valid %options are: |
1641
|
|
|
|
|
|
|
|
1642
|
|
|
|
|
|
|
=over |
1643
|
|
|
|
|
|
|
|
1644
|
|
|
|
|
|
|
=item condense |
1645
|
|
|
|
|
|
|
|
1646
|
|
|
|
|
|
|
Character width condense/expand factor (0.1-0.9 = condense, 1 = normal/default, |
1647
|
|
|
|
|
|
|
1.1+ = expand). It is the multiplier to apply to the width of each character. |
1648
|
|
|
|
|
|
|
|
1649
|
|
|
|
|
|
|
=item oblique |
1650
|
|
|
|
|
|
|
|
1651
|
|
|
|
|
|
|
Italic angle (+/- degrees, default 0), sets B of character box. |
1652
|
|
|
|
|
|
|
|
1653
|
|
|
|
|
|
|
=item bold |
1654
|
|
|
|
|
|
|
|
1655
|
|
|
|
|
|
|
Emboldening factor (0.1+, bold = 1, heavy = 2, ...), additional thickness to |
1656
|
|
|
|
|
|
|
draw outline of character (with a heavier B) before filling. |
1657
|
|
|
|
|
|
|
|
1658
|
|
|
|
|
|
|
=item space |
1659
|
|
|
|
|
|
|
|
1660
|
|
|
|
|
|
|
Additional character spacing in milliems (0-1000) |
1661
|
|
|
|
|
|
|
|
1662
|
|
|
|
|
|
|
=item caps |
1663
|
|
|
|
|
|
|
|
1664
|
|
|
|
|
|
|
0 for normal text, 1 for small caps. |
1665
|
|
|
|
|
|
|
Implemented by asking the font what the uppercased translation (single |
1666
|
|
|
|
|
|
|
character) is for a given character, and outputting it at 80% height and |
1667
|
|
|
|
|
|
|
88% width (heavier vertical stems are better looking than a straight 80% |
1668
|
|
|
|
|
|
|
scale). |
1669
|
|
|
|
|
|
|
|
1670
|
|
|
|
|
|
|
Note that only lower case letters which appear in the "standard" font (plane 0 |
1671
|
|
|
|
|
|
|
for core fonts and PS fonts) will be small-capped. This may include eszett |
1672
|
|
|
|
|
|
|
(German sharp s), which becomes SS, and dotless i and j which become I and J |
1673
|
|
|
|
|
|
|
respectively. There are many other accented Latin alphabet letters which I |
1674
|
|
|
|
|
|
|
show up in planes 1 and higher. Ligatures (e.g., ij and ffl) do not have |
1675
|
|
|
|
|
|
|
uppercase equivalents, nor does a long s. If you have text which includes such |
1676
|
|
|
|
|
|
|
characters, you may want to consider preprocessing it to replace them with |
1677
|
|
|
|
|
|
|
Latin character expansions (e.g., i+j and f+f+l) before small-capping. |
1678
|
|
|
|
|
|
|
|
1679
|
|
|
|
|
|
|
=back |
1680
|
|
|
|
|
|
|
|
1681
|
|
|
|
|
|
|
Note that I fonts (created with the C method) do B work |
1682
|
|
|
|
|
|
|
properly with C. This is due to a different internal structure of the |
1683
|
|
|
|
|
|
|
I fonts, as compared to I, I, and I base fonts. |
1684
|
|
|
|
|
|
|
If you require a synthesized (modified) CJK font, you might try finding the |
1685
|
|
|
|
|
|
|
TTF or OTF original, use C to create the base font, and running |
1686
|
|
|
|
|
|
|
C against that, in the manner described for embedding L. |
1687
|
|
|
|
|
|
|
|
1688
|
|
|
|
|
|
|
See also L |
1689
|
|
|
|
|
|
|
|
1690
|
|
|
|
|
|
|
=head2 IMAGE METHODS |
1691
|
|
|
|
|
|
|
|
1692
|
|
|
|
|
|
|
This is additional information on enhanced libraries available for TIFF and |
1693
|
|
|
|
|
|
|
PNG images. See specific information listings for GD, GIF, JPEG, and PNM image |
1694
|
|
|
|
|
|
|
formats. In addition, see C for an example of placing an |
1695
|
|
|
|
|
|
|
image on a page, as well as using in a "Form". |
1696
|
|
|
|
|
|
|
|
1697
|
|
|
|
|
|
|
=head3 Why is my image flipped or rotated? |
1698
|
|
|
|
|
|
|
|
1699
|
|
|
|
|
|
|
Something not uncommonly seen when using JPEG photos in a PDF is that the |
1700
|
|
|
|
|
|
|
images will be rotated and/or mirrored (flipped). This may happen when using |
1701
|
|
|
|
|
|
|
TIFF images too. What happens is that the camera stores an image just as it |
1702
|
|
|
|
|
|
|
comes off the CCD sensor, regardless of the camera orientation, and does not |
1703
|
|
|
|
|
|
|
rotate it to the correct orientation! It I store a separate |
1704
|
|
|
|
|
|
|
"orientation" flag to suggest how the image might be corrected, but not all |
1705
|
|
|
|
|
|
|
image processing obeys this flag (PDF::Builder does B.). For example, if |
1706
|
|
|
|
|
|
|
you take a "portrait" (tall) photo of a tree (with the phone held vertically), |
1707
|
|
|
|
|
|
|
and then use it in a PDF, the tree may appear to have been cut down! (appears |
1708
|
|
|
|
|
|
|
in landscape mode) |
1709
|
|
|
|
|
|
|
|
1710
|
|
|
|
|
|
|
I have found some code that should allow the C or C routine |
1711
|
|
|
|
|
|
|
to auto-rotate to (supposedly) the correct orientation, by looking for the Exif |
1712
|
|
|
|
|
|
|
metadata "Orientation" tag in the file. However, three problems arise: |
1713
|
|
|
|
|
|
|
B<1)> if a photo has been edited, and rotated or flipped in the process, there is no guarantee that the Orientation tag has been corrected. |
1714
|
|
|
|
|
|
|
B<2)> more than one Orientation tag may exist (e.g., in the binary APP1/Exif header, I in XML data), and they may not agree with each other -- which should be used? |
1715
|
|
|
|
|
|
|
B<3)> the code would need to uncompress the raster data, swap and/or transpose rows and/or columns, and recompress the raster data for inclusion into the PDF. This is costly and error-prone. |
1716
|
|
|
|
|
|
|
In any case, the user would need to be able to override any auto-rotate function. |
1717
|
|
|
|
|
|
|
|
1718
|
|
|
|
|
|
|
For the time being, PDF::Builder will simply leave it up to the user of the |
1719
|
|
|
|
|
|
|
library to take care of rotating and/or flipping an image which displays |
1720
|
|
|
|
|
|
|
incorrectly. It is possible that we will consider adding some sort of query or warning that the image appears to I be "normally" oriented (Orientation value 1 or "Top-left"), according to the Orientation flag. You can consider either (re-)saving the photo in an editor such as PhotoShop or GIMP, or using PDF::Builder code similar to the following (for images rotated 180 degrees): |
1721
|
|
|
|
|
|
|
|
1722
|
|
|
|
|
|
|
$pW = 612; $pH = 792; # page dimensions (US Letter) |
1723
|
|
|
|
|
|
|
my $img = $pdf->image_jpeg("AliceLake.jpeg"); |
1724
|
|
|
|
|
|
|
# raw size WxH 4032x3024, scaled down to 504x378 |
1725
|
|
|
|
|
|
|
$sW = 4032/8; $sH = 3024/8; |
1726
|
|
|
|
|
|
|
# intent is to center on US Letter sized page (LL at 54,207) |
1727
|
|
|
|
|
|
|
# Orientation flag on this image is 3 (rotated 180 degrees). |
1728
|
|
|
|
|
|
|
# if naively displayed (just $gfx->image call), it will be upside down |
1729
|
|
|
|
|
|
|
|
1730
|
|
|
|
|
|
|
$gfx->save(); |
1731
|
|
|
|
|
|
|
|
1732
|
|
|
|
|
|
|
## method 0: simple display, is rotated 180 degrees! |
1733
|
|
|
|
|
|
|
#$gfx->image($img, ($pW-$sW)/2,($pH-$sH)/2, $sW,$sH); |
1734
|
|
|
|
|
|
|
|
1735
|
|
|
|
|
|
|
## method 1: translate, then rotate |
1736
|
|
|
|
|
|
|
#$gfx->translate($pW,$pH); # to new origin (media UR corner) |
1737
|
|
|
|
|
|
|
#$gfx->rotate(180); # rotate around new origin |
1738
|
|
|
|
|
|
|
#$gfx->image($img, ($pW-$sW)/2,($pH-$sH)/2, $sW,$sH); |
1739
|
|
|
|
|
|
|
# image's UR corner, not LL |
1740
|
|
|
|
|
|
|
|
1741
|
|
|
|
|
|
|
# method 2: rotate, then translate |
1742
|
|
|
|
|
|
|
$gfx->rotate(180); # rotate around current origin |
1743
|
|
|
|
|
|
|
$gfx->translate(-$sW,-$sH); # translate in rotated coordinates |
1744
|
|
|
|
|
|
|
$gfx->image($img, -($pW-$sW)/2,-($pH-$sH)/2, $sW,$sH); |
1745
|
|
|
|
|
|
|
# image's UR corner, not LL |
1746
|
|
|
|
|
|
|
|
1747
|
|
|
|
|
|
|
## method 3: flip (mirror) twice |
1748
|
|
|
|
|
|
|
#$scale = 1; # not rescaling here |
1749
|
|
|
|
|
|
|
#$size_page = $pH/$scale; |
1750
|
|
|
|
|
|
|
#$invScale = 1.0/$scale; |
1751
|
|
|
|
|
|
|
#$gfx->add("-$invScale 0 0 -$invScale 0 $size_page cm"); |
1752
|
|
|
|
|
|
|
#$gfx->image($img, -($pW-$sW)/2-$sW,($pH-$sH)/2, $sW,$sH); |
1753
|
|
|
|
|
|
|
|
1754
|
|
|
|
|
|
|
$gfx->restore(); |
1755
|
|
|
|
|
|
|
|
1756
|
|
|
|
|
|
|
If your image is also mirrored (flipped about an axis), simple rotation will |
1757
|
|
|
|
|
|
|
not suffice. You could do something with a reversal of the coordinate system, as in "method 3" above (see L). To mirror only left/right, the second C<$invScale> would be positive; to mirror only top/bottom, the first would be positive. If all else fails, you could save a mirrored copy in a photo editor. |
1758
|
|
|
|
|
|
|
90 or 270 degree rotations will require a C call, possibly with "cm" usage to reverse mirroring. |
1759
|
|
|
|
|
|
|
Incidentally, do not confuse this issue with the coordinate flipping performed |
1760
|
|
|
|
|
|
|
by some Chrome browsers when printing a page to PDF. |
1761
|
|
|
|
|
|
|
|
1762
|
|
|
|
|
|
|
Note that TIFF images may have the same rotation/mirroring problems as JPEG, |
1763
|
|
|
|
|
|
|
which is not surprising, as the Exif format was lifted from TIFF for use in |
1764
|
|
|
|
|
|
|
JPEG. The cure will be similar to JPEG's. |
1765
|
|
|
|
|
|
|
|
1766
|
|
|
|
|
|
|
=head3 TIFF Images |
1767
|
|
|
|
|
|
|
|
1768
|
|
|
|
|
|
|
Note that the Graphics::TIFF support library does B currently permit a |
1769
|
|
|
|
|
|
|
filehandle for C<$file>. |
1770
|
|
|
|
|
|
|
|
1771
|
|
|
|
|
|
|
PDF::Builder will use the Graphics::TIFF support library for TIFF functions, if |
1772
|
|
|
|
|
|
|
it is available, unless explicitly told not to. Your code can test whether |
1773
|
|
|
|
|
|
|
Graphics::TIFF is available by examining C<< $tiff->usesLib() >> or |
1774
|
|
|
|
|
|
|
C<< $pdf->LA_GT() >>. |
1775
|
|
|
|
|
|
|
|
1776
|
|
|
|
|
|
|
=over |
1777
|
|
|
|
|
|
|
|
1778
|
|
|
|
|
|
|
=item = -1 |
1779
|
|
|
|
|
|
|
|
1780
|
|
|
|
|
|
|
Graphics::TIFF I installed, but your code has specified C, to |
1781
|
|
|
|
|
|
|
I use it. The old, pure Perl, code (buggy!) will be used instead, as if |
1782
|
|
|
|
|
|
|
Graphics::TIFF was not installed. |
1783
|
|
|
|
|
|
|
|
1784
|
|
|
|
|
|
|
=item = 0 |
1785
|
|
|
|
|
|
|
|
1786
|
|
|
|
|
|
|
Graphics::TIFF is I installed. Not all systems are able to successfully |
1787
|
|
|
|
|
|
|
install this package, as it requires libtiff.a. |
1788
|
|
|
|
|
|
|
|
1789
|
|
|
|
|
|
|
=item = 1 |
1790
|
|
|
|
|
|
|
|
1791
|
|
|
|
|
|
|
Graphics::TIFF is installed and is being used. |
1792
|
|
|
|
|
|
|
|
1793
|
|
|
|
|
|
|
=back |
1794
|
|
|
|
|
|
|
|
1795
|
|
|
|
|
|
|
Options: |
1796
|
|
|
|
|
|
|
|
1797
|
|
|
|
|
|
|
=over |
1798
|
|
|
|
|
|
|
|
1799
|
|
|
|
|
|
|
=item nouseGT => 1 |
1800
|
|
|
|
|
|
|
|
1801
|
|
|
|
|
|
|
Do B use the Graphics::TIFF library, even if it's available. Normally |
1802
|
|
|
|
|
|
|
you I want to use this library, but there may be cases where you don't, |
1803
|
|
|
|
|
|
|
such as when you want to use a file I instead of a I. |
1804
|
|
|
|
|
|
|
|
1805
|
|
|
|
|
|
|
=item silent => 1 |
1806
|
|
|
|
|
|
|
|
1807
|
|
|
|
|
|
|
Do not give the message that Graphics::TIFF is not B. This message |
1808
|
|
|
|
|
|
|
will be given only once, but you may want to suppress it, such as during |
1809
|
|
|
|
|
|
|
t-tests. |
1810
|
|
|
|
|
|
|
|
1811
|
|
|
|
|
|
|
=back |
1812
|
|
|
|
|
|
|
|
1813
|
|
|
|
|
|
|
=head3 PNG Images |
1814
|
|
|
|
|
|
|
|
1815
|
|
|
|
|
|
|
PDF::Builder will use the Image::PNG::Libpng support library for PNG functions, |
1816
|
|
|
|
|
|
|
if it is available, unless explicitly told not to. Your code can test whether |
1817
|
|
|
|
|
|
|
Image::PNG::Libpng is available by examining C<< $png->usesLib() >> or |
1818
|
|
|
|
|
|
|
C<< $pdf->LA_IPL() >>. |
1819
|
|
|
|
|
|
|
|
1820
|
|
|
|
|
|
|
=over |
1821
|
|
|
|
|
|
|
|
1822
|
|
|
|
|
|
|
=item = -1 |
1823
|
|
|
|
|
|
|
|
1824
|
|
|
|
|
|
|
Image::PNG::Libpng I installed, but your code has specified C, |
1825
|
|
|
|
|
|
|
to I use it. The old, pure Perl, code (slower and less capable) will be |
1826
|
|
|
|
|
|
|
used instead, as if Image::PNG::Libpng was not installed. |
1827
|
|
|
|
|
|
|
|
1828
|
|
|
|
|
|
|
=item = 0 |
1829
|
|
|
|
|
|
|
|
1830
|
|
|
|
|
|
|
Image::PNG::Libpng is I installed. Not all systems are able to successfully |
1831
|
|
|
|
|
|
|
install this package, as it requires libpng.a. |
1832
|
|
|
|
|
|
|
|
1833
|
|
|
|
|
|
|
=item = 1 |
1834
|
|
|
|
|
|
|
|
1835
|
|
|
|
|
|
|
Image::PNG::Libpng is installed and is being used. |
1836
|
|
|
|
|
|
|
|
1837
|
|
|
|
|
|
|
=back |
1838
|
|
|
|
|
|
|
|
1839
|
|
|
|
|
|
|
Options: |
1840
|
|
|
|
|
|
|
|
1841
|
|
|
|
|
|
|
=over |
1842
|
|
|
|
|
|
|
|
1843
|
|
|
|
|
|
|
=item nouseIPL => 1 |
1844
|
|
|
|
|
|
|
|
1845
|
|
|
|
|
|
|
Do B use the Image::PNG::Libpng library, even if it's available. Normally |
1846
|
|
|
|
|
|
|
you I want to use this library, when available, but there may be cases |
1847
|
|
|
|
|
|
|
where you don't. |
1848
|
|
|
|
|
|
|
|
1849
|
|
|
|
|
|
|
=item silent => 1 |
1850
|
|
|
|
|
|
|
|
1851
|
|
|
|
|
|
|
Do not give the message that Image::PNG::Libpng is not B. This |
1852
|
|
|
|
|
|
|
message will be given only once, but you may want to suppress it, such as |
1853
|
|
|
|
|
|
|
during t-tests. |
1854
|
|
|
|
|
|
|
|
1855
|
|
|
|
|
|
|
=item notrans => 1 |
1856
|
|
|
|
|
|
|
|
1857
|
|
|
|
|
|
|
No transparency -- ignore tRNS chunk if provided, ignore Alpha channel if |
1858
|
|
|
|
|
|
|
provided. |
1859
|
|
|
|
|
|
|
|
1860
|
|
|
|
|
|
|
=back |
1861
|
|
|
|
|
|
|
|
1862
|
|
|
|
|
|
|
=head2 USING SHAPER (HarfBuzz::Shaper library) |
1863
|
|
|
|
|
|
|
|
1864
|
|
|
|
|
|
|
# if HarfBuzz::Shaper is not installed, either bail out, or try to |
1865
|
|
|
|
|
|
|
# use regular TTF calls instead |
1866
|
|
|
|
|
|
|
my $rc; |
1867
|
|
|
|
|
|
|
$rc = eval { |
1868
|
|
|
|
|
|
|
require HarfBuzz::Shaper; |
1869
|
|
|
|
|
|
|
1; |
1870
|
|
|
|
|
|
|
}; |
1871
|
|
|
|
|
|
|
if (!defined $rc) { $rc = 0; } |
1872
|
|
|
|
|
|
|
if ($rc == 0) { |
1873
|
|
|
|
|
|
|
# bail out in some manner |
1874
|
|
|
|
|
|
|
} else { |
1875
|
|
|
|
|
|
|
# can use Shaper |
1876
|
|
|
|
|
|
|
} |
1877
|
|
|
|
|
|
|
|
1878
|
|
|
|
|
|
|
my $fontfile = '/WINDOWS/Fonts/times.ttf'; # used by both Shaper and textHS |
1879
|
|
|
|
|
|
|
my $fontsize = 15; # used by both Shaper and textHS |
1880
|
|
|
|
|
|
|
my $font = $pdf->ttfont($fontfile); |
1881
|
|
|
|
|
|
|
$text->font($font, $fontsize); |
1882
|
|
|
|
|
|
|
|
1883
|
|
|
|
|
|
|
my $hb = HarfBuzz::Shaper->new(); # only need to set up once |
1884
|
|
|
|
|
|
|
my %settings; # for textHS(), not Shaper |
1885
|
|
|
|
|
|
|
$settings{'dump'} = 1; # see the diagnostics |
1886
|
|
|
|
|
|
|
$settings{'script'} = 'Latn'; |
1887
|
|
|
|
|
|
|
$settings('dir'} = 'L'; # LTR |
1888
|
|
|
|
|
|
|
$settings{'features'} = (); # required |
1889
|
|
|
|
|
|
|
|
1890
|
|
|
|
|
|
|
# -- set language (override automatic setting) |
1891
|
|
|
|
|
|
|
#$settings{'language'} = 'en'; |
1892
|
|
|
|
|
|
|
#$hb->set_language( 'en_US' ); |
1893
|
|
|
|
|
|
|
# -- turn OFF ligatures |
1894
|
|
|
|
|
|
|
#push @{ $settings{'features'} }, 'liga'; |
1895
|
|
|
|
|
|
|
#$hb->add_features( 'liga' ); |
1896
|
|
|
|
|
|
|
# -- turn OFF kerning |
1897
|
|
|
|
|
|
|
#push @{ $settings{'features'} }, 'kern'; |
1898
|
|
|
|
|
|
|
#$hb->add_features( 'kern' ); |
1899
|
|
|
|
|
|
|
$hb->set_font($fontfile); |
1900
|
|
|
|
|
|
|
$hb->set_size($fontsize); |
1901
|
|
|
|
|
|
|
$hb->set_text("Let's eat waffles in the field for brunch."); |
1902
|
|
|
|
|
|
|
# expect ffl and fi ligatures, and perhaps some kerning |
1903
|
|
|
|
|
|
|
|
1904
|
|
|
|
|
|
|
my $info = $hb->shaper(); |
1905
|
|
|
|
|
|
|
$text->textHS($info, \%settings); # strikethru, underline allowed |
1906
|
|
|
|
|
|
|
|
1907
|
|
|
|
|
|
|
The package HarfBuzz::Shaper may be optionally installed in order to use the |
1908
|
|
|
|
|
|
|
text-shaping capabilities of the HarfBuzz library. These include kerning and |
1909
|
|
|
|
|
|
|
ligatures in Western scripts (such as the Latin alphabet). More complex scripts |
1910
|
|
|
|
|
|
|
can be handled, such as Arabic family and Indic scripts, where multiple forms |
1911
|
|
|
|
|
|
|
of a character may be automatically selected, characters may be reordered, and |
1912
|
|
|
|
|
|
|
other modifications made. The examples/HarfBuzz.pl script gives some examples |
1913
|
|
|
|
|
|
|
of what may be done. |
1914
|
|
|
|
|
|
|
|
1915
|
|
|
|
|
|
|
Keep in mind that HarfBuzz works only with TrueType (.ttf) and OpenType (.otf) |
1916
|
|
|
|
|
|
|
font files. It will not work with PostScript (Type1), core, bitmapped, or CJK |
1917
|
|
|
|
|
|
|
fonts. Not all .ttf fonts have the instructions necessary to guide HarfBuzz, |
1918
|
|
|
|
|
|
|
but most proper .otf fonts do. In other words, there are no guarantees that a |
1919
|
|
|
|
|
|
|
particular font file will work with Shaper! |
1920
|
|
|
|
|
|
|
|
1921
|
|
|
|
|
|
|
The basic idea is to break up text into "chunks" which are of the same script |
1922
|
|
|
|
|
|
|
(alphabet), language, direction, font face, font size, and variant (italic, |
1923
|
|
|
|
|
|
|
bold, etc.). These could range from a single character to paragraph-length |
1924
|
|
|
|
|
|
|
strings of text. These are fed to HarfBuzz::Shaper, along with flags, the font |
1925
|
|
|
|
|
|
|
file to be used, and other supporting |
1926
|
|
|
|
|
|
|
information, to create an array of output glyphs. Each element is a hash |
1927
|
|
|
|
|
|
|
describing the glyph to be output, including its name (if available), its glyph |
1928
|
|
|
|
|
|
|
ID (number) in the selected font, its x and y displacement (usually 0), and |
1929
|
|
|
|
|
|
|
its "advance" x and y values, all in points. For horizontal languages (LTR and |
1930
|
|
|
|
|
|
|
RTL), the y advance is normally 0 and the x advance is the font's character |
1931
|
|
|
|
|
|
|
width, less any kerning amount. |
1932
|
|
|
|
|
|
|
|
1933
|
|
|
|
|
|
|
Shaper will attempt to figure out the script used and the text direction, based on the Unicode range; and a reasonable guess at the language used. The language |
1934
|
|
|
|
|
|
|
can be overridden, but currently the script and text direction cannot be |
1935
|
|
|
|
|
|
|
overridden. |
1936
|
|
|
|
|
|
|
|
1937
|
|
|
|
|
|
|
B the number of glyphs (array elements) may not be equal to |
1938
|
|
|
|
|
|
|
the number of Unicode points (characters) given in the chunk's text string! |
1939
|
|
|
|
|
|
|
Sometimes a character will be decomposed into several pieces (multiple glyphs); |
1940
|
|
|
|
|
|
|
sometimes multiple characters may be combined into a single ligature glyph; and |
1941
|
|
|
|
|
|
|
characters may be reordered (especially in Indic and Southeast Asian languages). |
1942
|
|
|
|
|
|
|
As well, for Right-to-Left (bidirectional) scripts such as Hebrew and Arabic |
1943
|
|
|
|
|
|
|
families, the text is output in Left-to-Right order (reversed from the input). |
1944
|
|
|
|
|
|
|
|
1945
|
|
|
|
|
|
|
With due care, a Shaper array can be manipulated in code. The elements are more |
1946
|
|
|
|
|
|
|
or less independent of each other, so elements can be modified, rearranged, |
1947
|
|
|
|
|
|
|
inserted, or deleted. You might adjust the position of a glyph with 'dx' and |
1948
|
|
|
|
|
|
|
'dy' hash elements. The 'ax' value should be left alone, so that the wrong |
1949
|
|
|
|
|
|
|
kerning isn't calculated, but you might need to adjust the "advance x" value by |
1950
|
|
|
|
|
|
|
means of one of the following: |
1951
|
|
|
|
|
|
|
|
1952
|
|
|
|
|
|
|
=over |
1953
|
|
|
|
|
|
|
|
1954
|
|
|
|
|
|
|
=item B is a value to be I for 'ax' (points) |
1955
|
|
|
|
|
|
|
|
1956
|
|
|
|
|
|
|
=item B is a I value (I) of the original 'ax' |
1957
|
|
|
|
|
|
|
|
1958
|
|
|
|
|
|
|
=item B I 'ax' by the value (points). If negative, increase 'ax' |
1959
|
|
|
|
|
|
|
|
1960
|
|
|
|
|
|
|
=item B I 'ax' by the given I. Again, negative increases 'ax' |
1961
|
|
|
|
|
|
|
|
1962
|
|
|
|
|
|
|
=back |
1963
|
|
|
|
|
|
|
|
1964
|
|
|
|
|
|
|
B a given character's glyph ID is I necessarily going to be the |
1965
|
|
|
|
|
|
|
same between any two fonts! For example, an ASCII space (U+0020) might be |
1966
|
|
|
|
|
|
|
C0001E> in one font, and C0003E> in another font (even one |
1967
|
|
|
|
|
|
|
closely related!). A U+00A0 required blank (non-breaking space) may be output |
1968
|
|
|
|
|
|
|
as a regular ASCII space U+0020. Take care if you need to find a particular |
1969
|
|
|
|
|
|
|
glyph in the array, especially if the number of elements don't match. Consider |
1970
|
|
|
|
|
|
|
making a text string of "marker" characters (space, nbsp, hyphen, soft hyphen, |
1971
|
|
|
|
|
|
|
etc.) and processing it through HarfBuzz::Shaper to get the corresponding |
1972
|
|
|
|
|
|
|
glyph numbers. You may have to count spaces, say, to see where you could break |
1973
|
|
|
|
|
|
|
a glyph array to fit a line. |
1974
|
|
|
|
|
|
|
|
1975
|
|
|
|
|
|
|
The C method uses the same inputs as does C. |
1976
|
|
|
|
|
|
|
Like C, it returns the chunk length in points. Unlike |
1977
|
|
|
|
|
|
|
C, you cannot override the glyph array's font, font size, etc. |
1978
|
|
|
|
|
|
|
|
1979
|
|
|
|
|
|
|
Once you have your (possibly modified) array of glyphs, you feed it to the |
1980
|
|
|
|
|
|
|
C method to render it to the page. Remember that this method handles |
1981
|
|
|
|
|
|
|
only a single line of text; it does not do line splitting or fitting -- that |
1982
|
|
|
|
|
|
|
I currently need to do manually. For Western scripts (e.g., Latin), that |
1983
|
|
|
|
|
|
|
might not be too difficult, but for other scripts that involve extensive |
1984
|
|
|
|
|
|
|
modification of the raw characters, it may be quite difficult to split |
1985
|
|
|
|
|
|
|
I, but you still may be able to split at inter-word spaces. |
1986
|
|
|
|
|
|
|
|
1987
|
|
|
|
|
|
|
A useful, but not exhaustive, set of functions are allowed by C use. |
1988
|
|
|
|
|
|
|
Support includes direction setting (top-to-bottom and bottom-to-top directions, |
1989
|
|
|
|
|
|
|
e.g., for Far Eastern languages in traditional orientation), and explicit |
1990
|
|
|
|
|
|
|
script names and language (depending on what support HarfBuzz itself gives). |
1991
|
|
|
|
|
|
|
B supported are features such as discretionary ligatures and manual |
1992
|
|
|
|
|
|
|
selection of glyphs (e.g., swashes and alternate forms). |
1993
|
|
|
|
|
|
|
|
1994
|
|
|
|
|
|
|
Currently, C can only handle a single text string. We are looking at |
1995
|
|
|
|
|
|
|
how fitting to a line length (splitting up an array) could be done, as well as |
1996
|
|
|
|
|
|
|
how words might be split on hard and soft hyphens. At some point, full paragraph |
1997
|
|
|
|
|
|
|
and page shaping could be possible. |
1998
|
|
|
|
|
|
|
|
1999
|
|
|
|
|
|
|
=cut |
2000
|
|
|
|
|
|
|
|
2001
|
|
|
|
0
|
|
|
sub _docs { |
2002
|
|
|
|
|
|
|
# dummy stub |
2003
|
|
|
|
|
|
|
} |
2004
|
|
|
|
|
|
|
|
2005
|
|
|
|
|
|
|
1; |