File Coverage

blib/lib/PDF/Builder/Docs.pm
Criterion Covered Total %
statement 6 6 100.0
branch n/a
condition n/a
subroutine 2 3 66.6
pod n/a
total 8 9 88.8


line stmt bran cond sub pod time code
1             package PDF::Builder::Docs;
2              
3 1     1   2786 use strict;
  1         2  
  1         59  
4 1     1   7 use warnings;
  1         3  
  1         351  
5              
6             our $VERSION = '3.023'; # VERSION
7             our $LAST_UPDATE = '3.023'; # 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 to match up with available
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<-encode> (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.
513              
514             At Simms's request, the name of the new offering was changed from PDF::API4
515             to PDF::Builder, to reduce the chance of confusion due to parallel development.
516             Perry's intent is to keep all internal methods as upwardly compatible with
517             PDF::API2 as possible, although it is likely that there will be some drift
518             (incompatibilities) over time. At least initially, any program written based on
519             PDF::API2 should be convertible to PDF::Builder simply by changing "API2"
520             anywhere it occurs to "Builder". See the INFO/KNOWN_INCOMP known
521             incompatibilities file for further information.
522              
523             =head3 Thanks...
524              
525             Many users have helped out by reporting bugs and requesting enhancements. A
526             special shout out goes to those who have contributed code and tests, or
527             coordinated their package development with the needs of PDF::Builder:
528             Ben Bullock, Cary Gravel, Gregor Herrmann, Petr Pisar, Jeffrey Ratcliffe,
529             Steve Simms (via PDF::API2 fixes), and Johan Vromans.
530             Drop me a line if I've overlooked your contribution!
531              
532             =head1 DETAILED NOTES ON METHODS
533              
534             =head2 After saving a file...
535              
536             Note that a PDF object such as C<$pdf> cannot continue to be used after saving
537             an output PDF file or string with $pdf->C, C, or
538             C. There is some cleanup and other operations done internally
539             which make the object unusable for further operations. You will likely receive
540             an error message about B if
541             you try to keep using a PDF object.
542              
543             =head2 IntegrityCheck
544              
545             The PDF::Builder methods that open an existing PDF file, pass it by the
546             integrity checker method, C<$self-EIntegrityCheck(level, content)>. This method
547             servers two purposes: 1) to find any C settings that override the
548             PDF version found in the PDF heading, and 2) perform some basic validations on
549             the contents of the PDF.
550              
551             The C parameter accepts the following values:
552              
553             =over
554              
555             =item 0 = Do not output any diagnostic messages; just return any version override.
556              
557             =item 1 = Output error-level (serious) diagnostic messages, as well as returning any version override.
558              
559             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.
560              
561             =item 2 = Output error- (serious) and warning- (less serious) level diagnostic messages, as well as returning any version override. B
562              
563             =item 3 = Output error- (serious), warning- (less serious), and note- (informational) level diagnostic messages, as well as returning any version override.
564              
565             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.
566              
567             =item 4 = Output error-, warning-, and note-level diagnostic messages, as well as returning any version override. Also dump the diagnostic data structure.
568              
569             =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).
570              
571             =back
572              
573             The version is a string (e.g., '1.5') if found, otherwise C (undefined value) is returned.
574              
575             For controlling the "automatic" call to IntegrityCheck (via opens), the level
576             may be given with the option (flag) C<-diaglevel =E I>, where C is between 0 and 5.
577              
578             =head2 Preferences - set user display preferences
579              
580             =over
581              
582             =item $pdf->preferences(%options)
583              
584             Controls viewing preferences for the PDF.
585              
586             =back
587              
588             =head3 Page Mode Options
589              
590             =over
591              
592             =over
593              
594             =item -fullscreen
595              
596             Full-screen mode, with no menu bar, window controls, or any other window visible.
597              
598             =item -thumbs
599              
600             Thumbnail images visible.
601              
602             =item -outlines
603              
604             Document outline visible.
605              
606             =back
607              
608             =back
609              
610             =head3 Page Layout Options
611              
612             =over
613              
614             =over
615              
616             =item -singlepage
617              
618             Display one page at a time.
619              
620             =item -onecolumn
621              
622             Display the pages in one column.
623              
624             =item -twocolumnleft
625              
626             Display the pages in two columns, with oddnumbered pages on the left.
627              
628             =item -twocolumnright
629              
630             Display the pages in two columns, with oddnumbered pages on the right.
631              
632             =back
633              
634             =back
635              
636             =head3 Viewer Options
637              
638             =over
639              
640             =over
641              
642             =item -hidetoolbar
643              
644             Specifying whether to hide tool bars.
645              
646             =item -hidemenubar
647              
648             Specifying whether to hide menu bars.
649              
650             =item -hidewindowui
651              
652             Specifying whether to hide user interface elements.
653              
654             =item -fitwindow
655              
656             Specifying whether to resize the document's window to the size of the displayed page.
657              
658             =item -centerwindow
659              
660             Specifying whether to position the document's window in the center of the screen.
661              
662             =item -displaytitle
663              
664             Specifying whether the window's title bar should display the
665             document title taken from the Title entry of the document information
666             dictionary.
667              
668             =item -afterfullscreenthumbs
669              
670             Thumbnail images visible after Full-screen mode.
671              
672             =item -afterfullscreenoutlines
673              
674             Document outline visible after Full-screen mode.
675              
676             =item -printscalingnone
677              
678             Set the default print setting for page scaling to none.
679              
680             =item -simplex
681              
682             Print single-sided by default.
683              
684             =item -duplexflipshortedge
685              
686             Print duplex by default and flip on the short edge of the sheet.
687              
688             =item -duplexfliplongedge
689              
690             Print duplex by default and flip on the long edge of the sheet.
691              
692             =back
693              
694             =back
695              
696             =head3 Initial Page Options
697              
698             =over
699              
700             =item -firstpage => [ $page, %options ]
701              
702             Specifying the page (either a page number or a page object) to be
703             displayed, plus one of the following options:
704              
705             =over
706              
707             =item -fit => 1
708              
709             Display the page designated by page, with its contents magnified just
710             enough to fit the entire page within the window both horizontally and
711             vertically. If the required horizontal and vertical magnification
712             factors are different, use the smaller of the two, centering the page
713             within the window in the other dimension.
714              
715             =item -fith => $top
716              
717             Display the page designated by page, with the vertical coordinate top
718             positioned at the top edge of the window and the contents of the page
719             magnified just enough to fit the entire width of the page within the
720             window.
721              
722             =item -fitv => $left
723              
724             Display the page designated by page, with the horizontal coordinate
725             left positioned at the left edge of the window and the contents of the
726             page magnified just enough to fit the entire height of the page within
727             the window.
728              
729             =item -fitr => [ $left, $bottom, $right, $top ]
730              
731             Display the page designated by page, with its contents magnified just
732             enough to fit the rectangle specified by the coordinates left, bottom,
733             right, and top entirely within the window both horizontally and
734             vertically. If the required horizontal and vertical magnification
735             factors are different, use the smaller of the two, centering the
736             rectangle within the window in the other dimension.
737              
738             =item -fitb => 1
739              
740             Display the page designated by page, with its contents magnified just
741             enough to fit its bounding box entirely within the window both
742             horizontally and vertically. If the required horizontal and vertical
743             magnification factors are different, use the smaller of the two,
744             centering the bounding box within the window in the other dimension.
745              
746             =item -fitbh => $top
747              
748             Display the page designated by page, with the vertical coordinate top
749             positioned at the top edge of the window and the contents of the page
750             magnified just enough to fit the entire width of its bounding box
751             within the window.
752              
753             =item -fitbv => $left
754              
755             Display the page designated by page, with the horizontal coordinate
756             left positioned at the left edge of the window and the contents of the
757             page magnified just enough to fit the entire height of its bounding
758             box within the window.
759              
760             =item -xyz => [ $left, $top, $zoom ]
761              
762             Display the page designated by page, with the coordinates (left, top)
763             positioned at the top-left corner of the window and the contents of
764             the page magnified by the factor zoom. A zero (0) value for any of the
765             parameters left, top, or zoom specifies that the current value of that
766             parameter is to be retained unchanged.
767              
768             =back
769              
770             =back
771              
772             =head3 Example
773              
774             $pdf->preferences(
775             -fullscreen => 1,
776             -onecolumn => 1,
777             -afterfullscreenoutlines => 1,
778             -firstpage => [$page, -fit => 1],
779             );
780              
781             =head2 info Example
782              
783             %h = $pdf->info(
784             'Author' => "Alfred Reibenschuh",
785             'CreationDate' => "D:20020911000000+01'00'",
786             'ModDate' => "D:YYYYMMDDhhmmssOHH'mm'",
787             'Creator' => "fredos-script.pl",
788             'Producer' => "PDF::Builder",
789             'Title' => "some Publication",
790             'Subject' => "perl ?",
791             'Keywords' => "all good things are pdf"
792             );
793             print "Author: $h{'Author'}\n";
794              
795             =head2 XMP XML example
796              
797             $xml = $pdf->xmpMetadata();
798             print "PDFs Metadata reads: $xml\n";
799             $xml=<
800            
801            
802            
803             xmlns:x='adobe:ns:meta/'
804             x:xmptk='XMP toolkit 2.9.1-14, framework 1.6'>
805            
806             xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
807             xmlns:iX='http://ns.adobe.com/iX/1.0/'>
808            
809             rdf:about='uuid:b8659d3a-369e-11d9-b951-000393c97fd8'
810             xmlns:pdf='http://ns.adobe.com/pdf/1.3/'
811             pdf:Producer='Acrobat Distiller 6.0.1 for Macintosh'>
812            
813             rdf:about='uuid:b8659d3a-369e-11d9-b951-000393c97fd8'
814             xmlns:xap='http://ns.adobe.com/xap/1.0/'
815             xap:CreateDate='2004-11-14T08:41:16Z'
816             xap:ModifyDate='2004-11-14T16:38:50-08:00'
817             xap:CreatorTool='FrameMaker 7.0'
818             xap:MetadataDate='2004-11-14T16:38:50-08:00'>
819            
820             rdf:about='uuid:b8659d3a-369e-11d9-b951-000393c97fd8'
821             xmlns:xapMM='http://ns.adobe.com/xap/1.0/mm/'
822             xapMM:DocumentID='uuid:919b9378-369c-11d9-a2b5-000393c97fd8'/>
823            
824             rdf:about='uuid:b8659d3a-369e-11d9-b951-000393c97fd8'
825             xmlns:dc='http://purl.org/dc/elements/1.1/'
826             dc:format='application/pdf'>
827            
828            
829             Adobe Portable Document Format (PDF)
830            
831            
832            
833            
834             Adobe Systems Incorporated
835            
836            
837            
838            
839             PDF Reference, version 1.6
840            
841            
842            
843            
844            
845            
846             EOT
847              
848             $xml = $pdf->xmpMetadata($xml);
849             print "PDF metadata now reads: $xml\n";
850              
851             =head2 "BOX" METHODS
852              
853             B Use care if specifying a different Media Box (or other "box")
854             for a page, than the global "box" setting, to define the whole "chain" of boxes
855             on the page, to avoid surprises. For example, to define a global Media Box
856             (paper size) and a global Crop Box, and then define a new page-level Media Box
857             I defining a new page-level Crop Box, may give odd results in the
858             resultant cropping. Such combinations are not well defined.
859              
860             All dimensions in boxes default to the default User Unit, which is points (1/72
861             inch). Note that the PDF specification limits sizes and coordinates to 14400
862             User Units (200 inches, for the default User Unit of one point), and Adobe
863             products (so far) follow this limit for Acrobat and Distiller. It is worth
864             noting that other PDF writers and readers may choose to ignore the 14400 unit
865             limit, with or without the use of a specified User Unit. Therefore, PDF::Builder
866             does not enforce any limits on coordinates -- it's I responsibility to
867             consider what readers and other PDF tools may be used with a PDF you produce!
868             Also note that earlier Acrobat readers had coordinate limits as small as 3240
869             User Units (45 inches), and I media size of 72 or 3 User Units.
870              
871             =head3 User Units
872              
873             =over
874              
875             =item $pdf->userunit($number)
876              
877             The default User Unit in the PDF coordinate system is one point (1/72 inch). You
878             can think of it as a scale factor to enable larger (or even, smaller) documents.
879             This method may be used (for PDF 1.6 and higher) to set the User Unit to some
880             number of points. For example, C will set the scale multiplier to
881             72.0 points per User Unit, or 1 inch to the User Unit. Any number greater than
882             zero is acceptable, although some readers and tools may not handle User Units of
883             less than 1.0 very well.
884              
885             Not all readers respect the User Unit, if you give one, or handle it in exactly
886             the same way. Adobe Distiller, for one, does not use it. How User Units are
887             handled may vary from reader to reader. Adobe Acrobat, at this writing, respects
888             User Unit in version 7.0 and up, but limits it to 75000 (giving a maximum
889             document size of 15 million inches or 236.7 miles or 381 km). Other readers and
890             PDF tools may allow a larger (or smaller) limit.
891              
892             B Some readers ignore a global
893             User Unit setting and do I have pages inherit it (PDF::Builder duplicates
894             it on each page to simulate inheritance). Some readers may give spurious
895             warnings about truncated content when a Media Box is changed while User Units
896             are being used. Some readers do strange things with Crop Boxes when a User Unit
897             is in effect.
898              
899             Depending on the reader used, the effect of a larger User Unit (greater than 1)
900             may mean lower resolution (chunkier or coarser appearance) in the rendered
901             document. If you're printing something the size of a highway billboard, this may
902             not matter to you, but you should be aware of the possibility (even with
903             fractional coordinates). Conversely, a User Unit of less than 1.0 (if permitted)
904             reduces the allowable size of your document, but I result in greater
905             resolution.
906              
907             A global (PDF level) User Unit setting is inherited by each page (an action by
908             PDF::Builder, not necessarily automatically done by the reader), or can be
909             overridden by calling userunit in the page. Do not give more than one global
910             userunit setting, as only the last one will be used.
911             Setting a page's User Unit (if C<< $page-> >> instead) is permitted (overriding
912             the global setting for this page). However, many sources recommend against
913             doing this, as results may not be as expected (once again, depending on the
914             quirks of the reader).
915              
916             Remember to call C I calling anything having to do with page
917             or box sizes, or coordinates. Especially when setting 'named' box sizes, the
918             methods need to know the current User Unit so that named page sizes (in points)
919             may be scaled down to the current User Unit.
920              
921             =back
922              
923             =head3 Media Box
924              
925             =over
926              
927             =item $pdf->mediabox($name)
928              
929             =item $pdf->mediabox($name, -orient => 'orientation' )
930              
931             =item $pdf->mediabox($w,$h)
932              
933             =item $pdf->mediabox($llx,$lly, $urx,$ury)
934              
935             =item ($llx,$lly, $urx,$ury) = $pdf->mediabox()
936              
937             Sets the global Media Box (or page's Media Box, if C<< $page-> >> instead).
938             This defines the width and height (or by corner
939             coordinates, or by standard name) of the output page itself, such as the
940             physical paper size. This is normally the largest of the "boxes". If any
941             subsidiary box (within it) exceeds the media box, the portion of the material
942             or boxes outside of the Media Box will be ignored. That is, the Media Box is
943             the One Box to Rule Them All, and is the overall limit for other boxes (some
944             documentation refers to the Media Box as "clipping" other boxes). In
945             addition, the Media Box defines the overall I for text and
946             graphics operations.
947              
948             If no arguments are given, the current Media Box (global or page) coordinates
949             are returned instead. The former C (page only) function is
950             B and will likely be removed some time in the future. In addition,
951             when I the Media Box, the resulting coordinates are returned. This
952             permits you to specify the page size by a name (alias) and get the dimensions
953             back, all in one call.
954              
955             Note that many printers can B print all the way to the
956             physical edge of the paper, so you should plan to leave some blank margin,
957             even outside of any crop marks and bleeds. Printers and on-screen readers are
958             free to discard any content found outside the Media Box, and printers may
959             discard some material just inside the Media Box.
960              
961             A I Media Box is B by the PDF spec; if not explicitly given,
962             PDF::Builder will set the global Media Box to US Letter size (8.5in x 11in).
963             This is the media size that will be used for all pages if you do not specify
964             a C call on a page. That is,
965             a global (PDF level) mediabox setting is inherited by each page, or can be
966             overridden by setting mediabox in the page. Do not give more than one global
967             mediabox setting, as only the last one will be used.
968              
969             If you give a single string name (e.g., 'A4'), you may optionally add an
970             orientation to turn the page 90 degrees into Landscape mode:
971             C<< -orient => 'L' >> or C<< -orient => 'l' >>. C<-orient> is the only option
972             recognized, and a string beginning with an 'L' or 'l' (for Landscape) is the
973             only value of interest (anything else is treated as Portrait mode). The I
974             axis still runs from 0 at the bottom of the page to what used to be the page
975             I (now, I) at the top, and likewise for the I axis: 0 at left
976             to (former) I at the right. That is, the coordinate system is the same
977             as before, except that the height and width are different.
978              
979             The lower left corner does not I to be 0,0. It can be any values you want,
980             including negative values (so long as the resulting media's sides are at least
981             one point long). C sets the coordinate system (including the origin)
982             of the graphics and text that will be drawn, as well as for subsequent "boxes".
983             It's even possible to give any two opposite corners (such as upper left and
984             lower right). The coordinate system will be rearranged (by the Reader) to
985             still be the conventional minimum C and C in the lower left (i.e., you
986             can't make C I from top to bottom!).
987              
988             B
989              
990             $pdf = PDF::Builder->new();
991             $pdf->mediabox('A4'); # A4 size (595 Pt wide by 842 Pt high)
992             ...
993             $pdf->saveas('our/new.pdf');
994              
995             $pdf = PDF::Builder->new();
996             $pdf->mediabox(595, 842); # A4 size, with implicit 0,0 LL corner
997             ...
998             $pdf->saveas('our/new.pdf');
999              
1000             $pdf = PDF::Builder->new;
1001             $pdf->mediabox(0, 0, 595, 842); # A4 size, with explicit 0,0 LL corner
1002             ...
1003             $pdf->saveas('our/new.pdf');
1004              
1005             See the L source code for the full list of
1006             supported names (aliases) and their dimensions in points. You are free to add
1007             additional paper sizes to this file, if you wish. You might want to do this if
1008             you frequently use a standard page size in rotated (Landscape) mode. See also
1009             the C call in L. These names (aliases) are
1010             also usable in other "box" calls, although useful only if the "box" is the same
1011             size as the full media (Media Box), and you don't mind their starting at 0,0.
1012              
1013             =back
1014              
1015             =head3 Crop Box
1016              
1017             =over
1018              
1019             =item $pdf->cropbox($name)
1020              
1021             =item $pdf->cropbox($name, -orient => 'orientation')
1022              
1023             =item $pdf->cropbox($w,$h)
1024              
1025             =item $pdf->cropbox($llx,$lly, $urx,$ury)
1026              
1027             =item ($llx,$lly, $urx,$ury) = $pdf->cropbox()
1028              
1029             Sets the global Crop Box (or page's Crop Box, if C<< $page-> >> instead).
1030             This will define the media size to which the output will
1031             later be I. Note that this does B itself output any crop marks
1032             to guide cutting of the paper! PDF Readers should consider this to be the
1033             I portion of the page, and anything found outside it I be clipped
1034             (invisible). By default, it is equal to the Media Box, but may be defined to be
1035             smaller, in the coordinate system set by the Media Box. A global setting will
1036             be inherited by each page, but can be overridden on a per-page basis.
1037              
1038             A Reader or Printer may choose to discard any clipped (invisible) part of the
1039             page, and show only the area I the Crop Box. For example, if your page
1040             Media Box is A4 (0,0 to 595,842 Points), and your Crop Box is (100,100 to
1041             495,742), a reader such as Adobe Acrobat Reader may show you a page 395 by
1042             642 Points in size (i.e., just the visible area of your page). Other Readers
1043             may show you the full media size (Media Box) and a 100 Point wide blank area
1044             (in this example) around the visible content.
1045              
1046             If no arguments are given, the current Crop Box (global or page) coordinates
1047             are returned instead. The former C (page only) function is
1048             B and will likely be removed some time in the future. If a Crop Box
1049             has not been defined, the Media Box coordinates (which always exist) will be
1050             returned instead. In addition,
1051             when I the Crop Box, the resulting coordinates are returned. This
1052             permits you to specify the crop box by a name (alias) and get the dimensions
1053             back, all in one call.
1054              
1055             Do not confuse the Crop Box with the C, which shows where printed
1056             paper is expected to actually be I. Some PDF Readers may reduce the
1057             visible "paper" background to the size of the crop box; others may simply omit
1058             any content outside it. Either way, you would lose any trim or crop marks,
1059             printer instructions, color alignment dots, or other content outside the Crop
1060             Box. I would be limit printing to the area where a
1061             printer I reliably put down ink, and leave white the edge areas where
1062             paper-handling mechanisms prevent ink or toner from being applied. This would
1063             keep you from accidentally putting valuable content in an area where a printer
1064             will refuse to print, yet permit you to include a bleed area and space for
1065             printer's marks and instructions. Needless to say, if your printer cannot print
1066             to the very edge of the paper, you will need to trim (cut) the printed sheets
1067             to get true bleeds.
1068              
1069             A global (PDF level) cropbox setting is inherited by each page, or can be
1070             overridden by setting cropbox in the page.
1071             As with C, only one crop box may be set at this (PDF) level.
1072             As with C, a named media size may have an orientation (l or L) for
1073             Landscape mode.
1074             Note that the PDF level global Crop Box will be used I the page gets
1075             its own Media Box. That is, the page's Crop Box inherits the global Crop Box,
1076             not the page Media Box, even if the page has its own media size! If you set the
1077             page's own Media Box, you should consider also explicitly setting the page
1078             Crop Box (and other boxes).
1079              
1080             =back
1081              
1082             =head3 Bleed Box
1083              
1084             =over
1085              
1086             =item $pdf->bleedbox($name)
1087              
1088             =item $pdf->bleedbox($name, -orient => 'orientation')
1089              
1090             =item $pdf->bleedbox($w,$h)
1091              
1092             =item $pdf->bleedbox($llx,$lly, $urx,$ury)
1093              
1094             =item ($llx,$lly, $urx,$ury) = $pdf->bleedbox()
1095              
1096             Sets the global Bleed Box (or page's Bleed Box, if C<< $page-> >> instead).
1097             This is typically used in printing on paper, where you want
1098             ink or color (such as thumb tabs) to be printed a bit beyond the final paper
1099             size, to ensure that the cut paper I (the cut goes I the ink),
1100             rather than accidentally leaving some white paper visible outside. Allow
1101             enough "bleed" over the expected trim line to account for minor variations in
1102             paper handling, folding, and cutting; to avoid showing white paper at the edge.
1103             The Bleed Box is where I could actually extend to; the Trim Box is
1104             normally within it, where the paper would actually be I. The default
1105             value is equal to the Crop Box, but is often a bit smaller. The space between
1106             the Bleed Box and the Crop Box is available for printer instructions, color
1107             alignment dots, etc., while crop marks (trim guides) are at least partly within
1108             the bleed area (and should be printed after content is printed).
1109              
1110             If no arguments are given, the current Bleed Box (global or page) coordinates
1111             are returned instead. The former C (page only) function is
1112             B and will likely be removed some time in the future. If a Bleed Box
1113             has not been defined, the Crop Box coordinates (if defined) will be returned,
1114             otherwise the Media Box coordinates (which always exist) will be returned.
1115             In addition, when I the Bleed Box, the resulting coordinates are
1116             returned. This permits you to specify the bleed box by a name (alias) and get
1117             the dimensions back, all in one call.
1118              
1119             A global (PDF level) bleedbox setting is inherited by each page, or can be
1120             overridden by setting bleedbox in the page.
1121             As with C, only one bleed box may be set at this (PDF) level.
1122             As with C, a named media size may have an orientation (l or L) for
1123             Landscape mode.
1124             Note that the PDF level global Bleed Box will be used I the page gets
1125             its own Crop Box. That is, the page's Bleed Box inherits the global Bleed Box,
1126             not the page Crop Box, even if the page has its own media size! If you set the
1127             page's own Media Box or Crop Box, you should consider also explicitly setting
1128             the page Bleed Box (and other boxes).
1129              
1130             =back
1131              
1132             =head3 Trim Box
1133              
1134             =over
1135              
1136             =item $pdf->trimbox($name)
1137              
1138             =item $pdf->trimbox($name, -orient => 'orientation')
1139              
1140             =item $pdf->trimbox($w,$h)
1141              
1142             =item $pdf->trimbox($llx,$lly, $urx,$ury)
1143              
1144             =item ($llx,$lly, $urx,$ury) = $pdf->trimbox()
1145              
1146             Sets the global Trim Box (or page's Trim Box, if C<< $page-> >> instead).
1147             This is supposed to be the actual dimensions of the
1148             finished page (after trimming of the paper). In some production environments,
1149             it is useful to have printer's instructions, cut marks, and so on outside of
1150             the trim box. The default value is equal to Crop Box, but is often a bit
1151             smaller than any Bleed Box, to allow the desired "bleed" effect.
1152              
1153             If no arguments are given, the current Trim Box (global or page) coordinates
1154             are returned instead. The former C (page only) function is
1155             B and will likely be removed some time in the future. If a Trim Box
1156             has not been defined, the Crop Box coordinates (if defined) will be returned,
1157             otherwise the Media Box coordinates (which always exist) will be returned.
1158             In addition, when I the Trim Box, the resulting coordinates are
1159             returned. This permits you to specify the trim box by a name (alias) and get
1160             the dimensions back, all in one call.
1161              
1162             A global (PDF level) trimbox setting is inherited by each page, or can be
1163             overridden by setting trimbox in the page.
1164             As with C, only one trim box may be set at this (PDF) level.
1165             As with C, a named media size may have an orientation (l or L) for
1166             Landscape mode.
1167             Note that the PDF level global Trim Box will be used I the page gets
1168             its own Crop Box. That is, the page's Trim Box inherits the global Trim Box,
1169             not the page Crop Box, even if the page has its own media size! If you set the
1170             page's own Media Box or Crop Box, you should consider also explicitly setting
1171             the page Trim Box (and other boxes).
1172              
1173             =back
1174              
1175             =head3 Art Box
1176              
1177             =over
1178              
1179             =item $pdf->artbox($name)
1180              
1181             =item $pdf->artbox($name, -orient => 'orientation')
1182              
1183             =item $pdf->artbox($w,$h)
1184              
1185             =item $pdf->artbox($llx,$lly, $urx,$ury)
1186              
1187             =item ($llx,$lly, $urx,$ury) = $pdf->artbox()
1188              
1189             Sets the global Art Box (or page's Art Box, if C<< $page-> >> instead).
1190             This is supposed to define "the extent of the page's
1191             I content (including [margins])". It might exclude some content,
1192             such as Headlines or headings. Any binding or punched-holes margin would
1193             typically be outside of the Art Box, as would be page numbers and running
1194             headers and footers. The default value is equal to the Crop Box, although
1195             normally it would be no larger than any Trim Box. The Art Box may often be
1196             used for defining "important" content (e.g., I advertisements) that
1197             may or may not be brought over to another page (e.g., N-up printing).
1198              
1199             If no arguments are given, the current Art Box (global or page) coordinates
1200             are returned instead. The former C (page only) function is
1201             B and will likely be removed some time in the future. If an Art Box
1202             has not been defined, the Crop Box coordinates (if defined) will be returned,
1203             otherwise the Media Box coordinates (which always exist) will be returned.
1204             In addition, when I the Art Box, the resulting coordinates are
1205             returned. This permits you to specify the art box by a name (alias) and get
1206             the dimensions back, all in one call.
1207              
1208             A global (PDF level) artbox setting is inherited by each page, or can be
1209             overridden by setting artbox in the page.
1210             As with C, only one art box may be set at this (PDF) level.
1211             As with C, a named media size may have an orientation (l or L) for
1212             Landscape mode.
1213             Note that the PDF level global Art Box will be used I the page gets
1214             its own Crop Box. That is, the page's Art Box inherits the global Art Box,
1215             not the page Crop Box, even if the page has its own media size! If you set the
1216             page's own Media Box or Crop Box, you should consider also explicitly setting
1217             the page Art Box (and other boxes).
1218              
1219             =back
1220              
1221             =head3 Suggested Box Usage
1222              
1223             See C for an example of using boxes.
1224              
1225             How you define your boxes (or let them default) is up to you, depending on
1226             whether you're duplex printing US Letter or A4 on your laser printer, to be
1227             spiral bound on the bind margin, or engaging a professional printer. In the
1228             latter case, discuss in advance with the print firm what capabilities (and
1229             limitations) they have
1230             and what information they need from a PDF file. For instance, they may not want
1231             a Crop Box defined, and may call for very specific box sizes. For large press
1232             runs, they may print multiple pages (N-up) duplexed on large web roll
1233             "signatures", which are then intricately folded and guillotined (trimmed) and
1234             bound together into books or magazines. You would usually just supply a PDF
1235             with all the pages; they would take care of the signature layout (which
1236             includes offsets and 180 degree rotations).
1237              
1238             (As an aside, don't count on a printer having
1239             any particular font available, so be sure to ask. Usually they will want you
1240             to embed all fonts used, but ask first, and double-check before handing over
1241             the print job! TTF/OTF fonts (C) are embedded by default, but other
1242             fonts (core, ps, bdf, cjk) are not! A printer I have a core font
1243             collection, but they are free to substitute a "workalike" font for any given
1244             core font, and the results may not match what you saw on your PC!)
1245              
1246             On the assumption that you're using a single sheet (US Letter or A4) laser or
1247             inkjet printer, are you planning to trim each sheet down to a smaller final
1248             size? If so, you can do true bleeds by defining a Trim Box and a slightly
1249             larger Bleed Box. You would print bleeds (all the way to the finished edge)
1250             out to the Bleed Box, but nothing is enforced about the Bleed Box. At the other
1251             end of the spectrum, you would define the Media
1252             Box to be the physical paper size being printed on. Most printers reserve a
1253             little space on the sides (and possibly top and bottom) for paper handling, so
1254             it is often good to define your Crop Box as the printable area. Remember that
1255             the Media Box sets the coordinate system used, so you still need to avoid
1256             going outside the Crop Box with content (most readers and printers will not
1257             show any ink outside of the Crop Box). Whether or not you define a Crop Box,
1258             you're going to almost always end up with white paper on at least the sides.
1259              
1260             For small in-house jobs, you probably won't need color alignment dots and other
1261             such professional instructions and information between the Bleed Box and the
1262             Crop Box, but crop marks for trimming (if used) should go just outside the Trim
1263             Box (partly or wholly within the Bleed Box), and
1264             be drawn I all content. If you're I trimming the paper, don't try
1265             to do any bleed effects (including solid background color pages/covers), as
1266             you will usually have a white edge around the
1267             sheet anyway. Don't count on a PDF document I being physically printed,
1268             and not just displayed (where you can do things like bleed all the way to the
1269             media edge). Finally, for single sheet printing, an Art Box is
1270             probably unnecessary, but if you're combining pages into N-up prints, or doing
1271             other manipulations, it may be useful.
1272              
1273             =head3 Box Inheritance
1274              
1275             What Media, Crop, Bleed, Trim, and Art Boxes a page gets can be a little
1276             complicated. Note that usually, only the Media and Crop Boxes will have a
1277             clear visual effect. The visual effect of the other boxes (if any) may be
1278             very subtle.
1279              
1280             First, everything is set at the global (PDF) level. The Media Box is always
1281             defined, and defaults to US Letter (8.5 inches wide by 11 inches high). The
1282             global Crop Box inherits the Media Box, unless explicitly defined. The Bleed,
1283             Trim, and Art Boxes inherit the Crop Box, unless explicitly defined. A global
1284             box should only be defined once, as the last one defined is the one that will
1285             be written to the PDF!
1286              
1287             Second, a page inherits the global boxes, for its initial settings. You may
1288             call any of the box set methods (C, C, etc.) to explicitly
1289             set (override) any box for I page. Note that setting a new Media Box for
1290             the page does B reset the page's Crop Box -- it still uses whatever it
1291             inherited from the global Crop Box. You would need to explicitly set the page's
1292             Crop Box if you want a different setting. Likewise, the page's Bleed, Trim, and
1293             Art Boxes will not be reset by a new page Crop Box -- they will still inherit
1294             from the global (PDF) settings.
1295              
1296             Third, the page Media Box (the one actually used for output pages), clips or
1297             limits all the other boxes to extend no larger than its size. For example, if
1298             the Media Box is US Letter, and you set a Crop Box of A4 size, the smaller of
1299             the two heights (11 inches) would be effective, and the smaller of the two
1300             widths (8.26 inches, 595 Points) would be effective.
1301             The I dimensions of a box are returned on query (get), not the
1302             I dimensions clipped by the Media Box.
1303              
1304             =head2 FONT METHODS
1305              
1306             =head3 Core Fonts
1307              
1308             Core fonts are limited to single byte encodings. You cannot use UTF-8 or other
1309             multibyte encodings with core fonts. The default encoding for the core fonts is
1310             WinAnsiEncoding (roughly the CP-1252 superset of ISO-8859-1). See the
1311             C<-encode> option below to change this encoding.
1312             See L method for information on
1313             accessing more than 256 glyphs in a font, using planes, I
1314             guarantee that future changes to font files will permit consistent results>.
1315              
1316             Note that core fonts use fixed lists of expected glyphs, along with metrics
1317             such as their widths. This may not exactly match up with whatever local font
1318             file is used by the PDF reader. It's usually pretty close, but many cases have
1319             been found where the list of glyphs is different between the core fonts and
1320             various local font files, so be aware of this.
1321              
1322             To allow UTF-8 text and extended glyph counts, you should
1323             consider replacing your use of core fonts with TrueType (.ttf) and OpenType
1324             (.otf) fonts. There are tools, such as I, which can do a fairly good
1325             (though, not perfect) job of converting a Type1 font library to OTF.
1326              
1327             B
1328              
1329             $font1 = $pdf->corefont('Times-Roman', -encode => 'latin2');
1330             $font2 = $pdf->corefont('Times-Bold');
1331             $font3 = $pdf->corefont('Helvetica');
1332             $font4 = $pdf->corefont('ZapfDingbats');
1333              
1334             Valid %options are:
1335              
1336             =over
1337              
1338             =item -encode
1339              
1340             Changes the encoding of the font from its default. Notice that the encoding
1341             (I the entire font's glyph list) is shown in a PDF object (record), listing
1342             256 glyphs associated with this encoding (I that are available in this
1343             font).
1344              
1345             =item -dokern
1346              
1347             Enables kerning if data is available.
1348              
1349             =back
1350              
1351             B
1352              
1353             Even though these are called "core" fonts, they are I shipped
1354             with PDF::Builder, but are expected to be found on the machine with the PDF
1355             reader. Most core fonts are installed with a PDF reader, and thus are not
1356             coordinated with PDF::Builder. PDF::Builder I ship with core font
1357             I files (width, glyph names, etc.), but these cannot be guaranteed to
1358             be in sync with what the PDF reader has installed!
1359              
1360             There are some 14 core fonts (regular, italic, bold, and bold-italic for
1361             Times [serif], Helvetica [sans serif], Courier [fixed pitch]; plus two symbol
1362             fonts) that are supposed to be available on any PDF reader, B
1363             fonts with very similar metrics are often substituted.> You should I count
1364             on any of the 15 Windows core fonts (Bank Gothic, Georgia, Trebuchet, Verdana,
1365             and two more symbol fonts) being present, especially on Linux, Mac, or other
1366             non-Windows platforms. Be aware if you are producing PDFs to be read on a
1367             variety of different systems!
1368              
1369             If you want to ensure the widest portability for a PDF document you produce,
1370             you should consider using TTF fonts (instead of core fonts) and embedding them
1371             in the document. This ensures that there will be no substitutions, that all
1372             metrics are known and match the glyphs, UTF-8 encoding can be used, and
1373             that the glyphs I be available on the reader's machine. At least on
1374             Windows platforms, most of the fonts are TTF anyway, which are used behind the
1375             scenes for "core" fonts, while missing most of the capabilities of TTF (now
1376             or possibly later in PDF::Builder) such as embedding, ligatures, UTF-8, etc.
1377             The downside is, obviously, that the resulting PDF file will be larger because
1378             it includes the font(s). There I also be copyright or licensing issues
1379             with the redistribution of font files in this manner (you might want to check,
1380             before widely distributing a PDF document with embedded fonts, although many
1381             I permit the part of the font used, to be embedded.).
1382              
1383             See also L.
1384              
1385             =head3 PS Fonts
1386              
1387             PS (T1) fonts are limited to single byte encodings. You cannot use UTF-8 or
1388             other multibyte encodings with T1 fonts.
1389             The default encoding for the T1 fonts is
1390             WinAnsiEncoding (roughly the CP-1252 superset of ISO-8859-1). See the
1391             C<-encode> option below to change this encoding.
1392             See L method for information on
1393             accessing more than 256 glyphs in a font, using planes, I
1394             guarantee that future changes to font files will permit consistent results>.
1395             B many Type1 fonts are limited to 256 glyphs, but some are available
1396             with more than 256 glyphs. Still, a maximum of 256 at a time are usable.
1397              
1398             C accepts both ASCII (.pfa) and binary (.pfb) Type1 glyph files.
1399             Font metrics can be supplied in either ASCII (.afm) or binary (.pfm) format,
1400             as can be seen in the examples given below. It is possible to use .pfa with .pfm
1401             and .pfb with .afm if that's what's available. The ASCII and binary files have
1402             the same content, just in different formats.
1403              
1404             To allow UTF-8 text and extended glyph counts in one font, you should
1405             consider replacing your use of Type1 fonts with TrueType (.ttf) and OpenType
1406             (.otf) fonts. There are tools, such as I, which can do a fairly good
1407             (though, not perfect) job of converting your font library to OTF.
1408              
1409             B
1410              
1411             $font1 = $pdf->psfont('Times-Book.pfa', -afmfile => 'Times-Book.afm');
1412             $font2 = $pdf->psfont('/fonts/Synest-FB.pfb', -pfmfile => '/fonts/Synest-FB.pfm');
1413              
1414             Valid %options are:
1415              
1416             =over
1417              
1418             =item -encode
1419              
1420             Changes the encoding of the font from its default. Notice that the encoding
1421             (I the entire font's glyph list) is shown in a PDF object (record), listing
1422             256 glyphs associated with this encoding (I that are available in this
1423             font).
1424              
1425             =item -afmfile
1426              
1427             Specifies the location of the I font metrics file (.afm). It may be used
1428             with either an ASCII (.pfa) or binary (.pfb) glyph file.
1429              
1430             =item -pfmfile
1431              
1432             Specifies the location of the I font metrics file (.pfm). It may be used
1433             with either an ASCII (.pfa) or binary (.pfb) glyph file.
1434              
1435             =item -dokern
1436              
1437             Enables kerning if data is available.
1438              
1439             =back
1440              
1441             B these T1 (Type1) fonts are I shipped with PDF::Builder, but are
1442             expected to be found on the machine with the PDF reader. Most PDF readers do
1443             not install T1 fonts, and it is up to the user of the PDF reader to install
1444             the needed fonts. Unlike TrueType fonts, PS (T1) fonts are not embedded in the
1445             PDF, and must be supplied on the Reader end.
1446              
1447             See also L.
1448              
1449             =head3 TrueType Fonts
1450              
1451             B BaseEncoding is I set by default for TrueType fonts, so B
1452             in the PDF isn't searchable> (by the PDF reader) unless a ToUnicode CMap is
1453             included. A ToUnicode CMap I included by default (-unicodemap set to 1) by
1454             PDF::Builder, but allows it to be disabled (for performance and file size
1455             reasons) by setting -unicodemap to 0. This will produce non-searchable text,
1456             which, besides being annoying to users, may prevent screen
1457             readers and other aids to disabled users from working correctly!
1458              
1459             B
1460              
1461             $font1 = $pdf->ttfont('Times.ttf');
1462             $font2 = $pdf->ttfont('Georgia.otf');
1463              
1464             Valid %options are:
1465              
1466             =over
1467              
1468             =item -encode
1469              
1470             Changes the encoding of the font from its default (WinAnsiEncoding).
1471              
1472             Note that for a single byte encoding (e.g., 'latin1'), you are limited to 256
1473             characters defined for that encoding. 'automap' does not work with TrueType.
1474             If you want more characters than that, use 'utf8' encoding with a UTF-8
1475             encoded text string.
1476              
1477             =item -isocmap
1478              
1479             Use the ISO Unicode Map instead of the default MS Unicode Map.
1480              
1481             =item -unicodemap
1482              
1483             If 1 (default), output ToUnicode CMap to permit text searches and screen
1484             readers. Set to 0 to save space by I including the ToUnicode CMap, but
1485             text searching and screen reading will not be possible.
1486              
1487             =item -dokern
1488              
1489             Enables kerning if data is available.
1490              
1491             =item -noembed
1492              
1493             Disables embedding of the font file. B
1494             as the glyphs provided on the PDF reader machine may not match what was used on
1495             the PDF writer machine (the one running PDF::Builder)!> If you know I
1496             that all PDF readers will be using the same TTF or OTF file you're using with
1497             PDF::Builder; not embedding the font may be acceptable, in return for a smaller
1498             PDF file size. Note that the Reader needs to know where to find the font file
1499             -- it can't be in any random place, but typically needs to be listed in a path
1500             that the Reader follows. Otherwise, it will be unable to render the text!
1501              
1502             The only value for the C<-noembed> flag currently checked for is B<1>, which
1503             means to I embed the font file in the PDF. Any other value currently
1504             results in the font file being embedded (by B), although in the future,
1505             other values might be given significance (such as checking permission bits).
1506              
1507             Some additional comments on embedding font file(s) into the PDF: besides
1508             substantially increasing the size of the PDF (even if the font is subsetted,
1509             by default), PDF::Builder does not check the font file for any flags indicating
1510             font licensing issues and limitations on use. A font foundry may not permit
1511             embedding at all, may permit a subset of the font to be embedded, may permit a
1512             full font to be embedded, and may specify what can be done with an embedded
1513             font (e.g., may or may not be extracted for further use beyond displaying this
1514             one PDF). When you choose to use (and embed) a font, you should be aware of any
1515             such licensing issues.
1516              
1517             =item -nosubset
1518              
1519             Disables subsetting of a TTF/OTF font, when embedded. By default, only the
1520             glyphs used by a document are included in the file, and I the entire font.
1521             This can result in a tremendous savings in PDF file size. If you intend to
1522             allow the PDF to be edited by users, not having the entire font glyph set
1523             available may cause problems, so be aware of that (and consider using
1524             C<< -nosubset => 1 >>. Setting this flag to any value results in the entire
1525             font glyph set being embedded in the file. It might be a good idea to use only
1526             the value B<1>, in case other values are assigned roles in the future.
1527              
1528             =item -debug
1529              
1530             If set to 1 (default is 0), diagnostic information is output about the CMap
1531             processing.
1532              
1533             =item -usecmf
1534              
1535             If set to 1 (default is 0), the first priority is to make use of one of the
1536             four C<.cmap> files for CJK fonts. This is the I way of processing TTF
1537             files. If, after all is said and done, a working I CMap hasn't been
1538             found (for -usecmf=>0), C will fall back to using a C<.cmap> file
1539             if possible.
1540              
1541             =item -cmaps
1542              
1543             This flag may be set to a string listing the Platform/Encoding pairs to look
1544             for of any internal CMaps in the font file, in the desired order (highest
1545             priority first). If one list (comma and/or space-separated pairs) is given, it
1546             is used for both Windows and non-Windows platforms (on which PDF::Builder is
1547             running, I the PDF reader's). Two lists, separated by a semicolon ; may be
1548             given, with the first being used for a Windows platform and the second for
1549             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>.
1550             Finally, instead of a P/E list, a string C may be given to tell it to
1551             simply call the Font::TTF C method to find a (preferably Windows)
1552             internal CMap. C<-cmaps> set to 'find_ms' would emulate the I way of
1553             looking for CMaps. Symbol fonts (3/0) always use find_ms(), and the new default
1554             lookup is (if C<.cmap> isn't used, see C<-usecmf>) to try to get a match with
1555             the default list for the appropriate OS. If none can be found, find_ms() is
1556             tried, and as last resort use the C<.cmap> (if available), even if C<-usecmf>
1557             is not 1.
1558              
1559             =back
1560              
1561             =head3 CJK Fonts
1562              
1563             B
1564              
1565             $font = $pdf->cjkfont('korean');
1566             $font = $pdf->cjkfont('traditional');
1567              
1568             Valid %options are:
1569              
1570             =over
1571              
1572             =item -encode
1573              
1574             Changes the encoding of the font from its default.
1575              
1576             =back
1577              
1578             B Unlike C, the font file is I embedded in the output
1579             PDF file. This is
1580             evidently behavior left over from the early days of CJK fonts, where the
1581             C and C were always external files, rather than internal tables.
1582             If you need a CJK-using PDF file to embed the font, for portability, you can
1583             create a PDF using C, and then use an external utility (e.g.,
1584             C) to embed the font in the PDF. It may also be possible to use
1585             C instead, to produce the PDF, provided you can deduce the correct
1586             font file name from examining the PDF file (e.g., on my Windows system, the
1587             "Ming" font would be C<< $font = $pdf->ttfont("C:/Program Files (x86)/Adobe/Acrobat Reader DC/Resource/CIDFont/AdobeMingStd-Light.otf") >>.
1588             Of course, the font file used would have to be C<.ttf> or C<.otf>.
1589             It may act a little differently than C (due a a different Cmap), but
1590             you I be able to embed the font file into the PDF.
1591              
1592             See also L
1593              
1594             =head3 Synthetic Fonts
1595              
1596             B BaseEncoding is I set by default for these fonts, so text
1597             in the PDF isn't searchable (by the PDF reader) unless a ToUnicode CMap is
1598             included. A ToUnicode CMap I included by default (-unicodemap set to 1) by
1599             PDF::Builder, but allows it to be disabled (for performance and file size
1600             reasons) by setting -unicodemap to 0. This will produce non-searchable text,
1601             which, besides being annoying to users, may prevent screen
1602             readers and other aids to disabled users from working correctly!
1603              
1604             B
1605              
1606             $cf = $pdf->corefont('Times-Roman', -encode => 'latin1');
1607             $sf = $pdf->synfont($cf, -condense => 0.85); # compressed 85%
1608             $sfb = $pdf->synfont($cf, -bold => 1); # embolden by 10em
1609             $sfi = $pdf->synfont($cf, -oblique => -12); # italic at -12 degrees
1610              
1611             Valid %options are:
1612              
1613             =over
1614              
1615             =item -condense
1616              
1617             Character width condense/expand factor (0.1-0.9 = condense, 1 = normal/default,
1618             1.1+ = expand). It is the multiplier to apply to the width of each character.
1619              
1620             =item -oblique
1621              
1622             Italic angle (+/- degrees, default 0), sets B of character box.
1623              
1624             =item -bold
1625              
1626             Emboldening factor (0.1+, bold = 1, heavy = 2, ...), additional thickness to
1627             draw outline of character (with a heavier B) before filling.
1628              
1629             =item -space
1630              
1631             Additional character spacing in milliems (0-1000)
1632              
1633             =item -caps
1634              
1635             0 for normal text, 1 for small caps.
1636             Implemented by asking the font what the uppercased translation (single
1637             character) is for a given character, and outputting it at 80% height and
1638             88% width (heavier vertical stems are better looking than a straight 80%
1639             scale).
1640              
1641             Note that only lower case letters which appear in the "standard" font (plane 0
1642             for core fonts and PS fonts) will be small-capped. This may include eszett
1643             (German sharp s), which becomes SS, and dotless i and j which become I and J
1644             respectively. There are many other accented Latin alphabet letters which I
1645             show up in planes 1 and higher. Ligatures (e.g., ij and ffl) do not have
1646             uppercase equivalents, nor does a long s. If you have text which includes such
1647             characters, you may want to consider preprocessing it to replace them with
1648             Latin character expansions (e.g., i+j and f+f+l) before small-capping.
1649              
1650             =back
1651              
1652             Note that I fonts (created with the C method) do B work
1653             properly with C. This is due to a different internal structure of the
1654             I fonts, as compared to I, I, and I base fonts.
1655             If you require a synthesized (modified) CJK font, you might try finding the
1656             TTF or OTF original, use C to create the base font, and running
1657             C against that, in the manner described for embedding L.
1658              
1659             See also L
1660              
1661             =head2 IMAGE METHODS
1662              
1663             This is additional information on enhanced libraries available for TIFF and
1664             PNG images. See specific information listings for GD, GIF, JPEG, and PNM image
1665             formats. In addition, see C for an example of placing an
1666             image on a page, as well as using in a "Form".
1667              
1668             =head3 Why is my image flipped or rotated?
1669              
1670             Something not uncommonly seen when using JPEG photos in a PDF is that the
1671             images will be rotated and/or mirrored (flipped). This may happen when using
1672             TIFF images too. What happens is that the camera stores an image just as it
1673             comes off the CCD sensor, regardless of the camera orientation, and does not
1674             rotate it to the correct orientation! It I store a separate
1675             "orientation" flag to suggest how the image might be corrected, but not all
1676             image processing obeys this flag (PDF::Builder does B.). For example, if
1677             you take a "portrait" (tall) photo of a tree (with the phone held vertically),
1678             and then use it in a PDF, the tree may appear to have been cut down! (appears
1679             in landscape mode)
1680              
1681             I have found some code that should allow the C or C routine
1682             to auto-rotate to (supposedly) the correct orientation, by looking for the Exif
1683             metadata "Orientation" tag in the file. However, three problems arise:
1684             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.
1685             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?
1686             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.
1687             In any case, the user would need to be able to override any auto-rotate function.
1688              
1689             For the time being, PDF::Builder will simply leave it up to the user of the
1690             library to take care of rotating and/or flipping an image which displays
1691             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):
1692              
1693             $pW = 612; $pH = 792; # page dimensions (US Letter)
1694             my $img = $pdf->image_jpeg("AliceLake.jpeg");
1695             # raw size WxH 4032x3024, scaled down to 504x378
1696             $sW = 4032/8; $sH = 3024/8;
1697             # intent is to center on US Letter sized page (LL at 54,207)
1698             # Orientation flag on this image is 3 (rotated 180 degrees).
1699             # if naively displayed (just $gfx->image call), it will be upside down
1700              
1701             $gfx->save();
1702            
1703             ## method 0: simple display, is rotated 180 degrees!
1704             #$gfx->image($img, ($pW-$sW)/2,($pH-$sH)/2, $sW,$sH);
1705              
1706             ## method 1: translate, then rotate
1707             #$gfx->translate($pW,$pH); # to new origin (media UR corner)
1708             #$gfx->rotate(180); # rotate around new origin
1709             #$gfx->image($img, ($pW-$sW)/2,($pH-$sH)/2, $sW,$sH);
1710             # image's UR corner, not LL
1711              
1712             # method 2: rotate, then translate
1713             $gfx->rotate(180); # rotate around current origin
1714             $gfx->translate(-$sW,-$sH); # translate in rotated coordinates
1715             $gfx->image($img, -($pW-$sW)/2,-($pH-$sH)/2, $sW,$sH);
1716             # image's UR corner, not LL
1717              
1718             ## method 3: flip (mirror) twice
1719             #$scale = 1; # not rescaling here
1720             #$size_page = $pH/$scale;
1721             #$invScale = 1.0/$scale;
1722             #$gfx->add("-$invScale 0 0 -$invScale 0 $size_page cm");
1723             #$gfx->image($img, -($pW-$sW)/2-$sW,($pH-$sH)/2, $sW,$sH);
1724              
1725             $gfx->restore();
1726              
1727             If your image is also mirrored (flipped about an axis), simple rotation will
1728             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.
1729             90 or 270 degree rotations will require a C call, possibly with "cm" usage to reverse mirroring.
1730             Incidentally, do not confuse this issue with the coordinate flipping performed
1731             by some Chrome browsers when printing a page to PDF.
1732              
1733             Note that TIFF images may have the same rotation/mirroring problems as JPEG,
1734             which is not surprising, as the Exif format was lifted from TIFF for use in
1735             JPEG. The cure will be similar to JPEG's.
1736              
1737             =head3 TIFF Images
1738              
1739             Note that the Graphics::TIFF support library does B currently permit a
1740             filehandle for C<$file>.
1741              
1742             PDF::Builder will use the Graphics::TIFF support library for TIFF functions, if
1743             it is available, unless explicitly told not to. Your code can test whether
1744             Graphics::TIFF is available by examining C<< $tiff->usesLib() >> or
1745             C<< $pdf->LA_GT() >>.
1746              
1747             =over
1748              
1749             =item = -1
1750              
1751             Graphics::TIFF I installed, but your code has specified C<-nouseGT>, to
1752             I use it. The old, pure Perl, code (buggy!) will be used instead, as if
1753             Graphics::TIFF was not installed.
1754              
1755             =item = 0
1756              
1757             Graphics::TIFF is I installed. Not all systems are able to successfully
1758             install this package, as it requires libtiff.a.
1759              
1760             =item = 1
1761              
1762             Graphics::TIFF is installed and is being used.
1763              
1764             =back
1765              
1766             Options:
1767              
1768             =over
1769              
1770             =item -nouseGT => 1
1771              
1772             Do B use the Graphics::TIFF library, even if it's available. Normally
1773             you I want to use this library, but there may be cases where you don't,
1774             such as when you want to use a file I instead of a I.
1775              
1776             =item -silent => 1
1777              
1778             Do not give the message that Graphics::TIFF is not B. This message
1779             will be given only once, but you may want to suppress it, such as during
1780             t-tests.
1781              
1782             =back
1783              
1784             =head3 PNG Images
1785              
1786             PDF::Builder will use the Image::PNG::Libpng support library for PNG functions,
1787             if it is available, unless explicitly told not to. Your code can test whether
1788             Image::PNG::Libpng is available by examining C<< $png->usesLib() >> or
1789             C<< $pdf->LA_IPL() >>.
1790              
1791             =over
1792              
1793             =item = -1
1794              
1795             Image::PNG::Libpng I installed, but your code has specified C<-nouseIPL>,
1796             to I use it. The old, pure Perl, code (slower and less capable) will be
1797             used instead, as if Image::PNG::Libpng was not installed.
1798              
1799             =item = 0
1800              
1801             Image::PNG::Libpng is I installed. Not all systems are able to successfully
1802             install this package, as it requires libpng.a.
1803              
1804             =item = 1
1805              
1806             Image::PNG::Libpng is installed and is being used.
1807              
1808             =back
1809              
1810             Options:
1811              
1812             =over
1813              
1814             =item -nouseIPL => 1
1815              
1816             Do B use the Image::PNG::Libpng library, even if it's available. Normally
1817             you I want to use this library, when available, but there may be cases
1818             where you don't.
1819              
1820             =item -silent => 1
1821              
1822             Do not give the message that Image::PNG::Libpng is not B. This
1823             message will be given only once, but you may want to suppress it, such as
1824             during t-tests.
1825              
1826             =item -notrans => 1
1827              
1828             No transparency -- ignore tRNS chunk if provided, ignore Alpha channel if
1829             provided.
1830              
1831             =back
1832              
1833             =head2 USING SHAPER (HarfBuzz::Shaper library)
1834              
1835             # if HarfBuzz::Shaper is not installed, either bail out, or try to
1836             # use regular TTF calls instead
1837             my $rc;
1838             $rc = eval {
1839             require HarfBuzz::Shaper;
1840             1;
1841             };
1842             if (!defined $rc) { $rc = 0; }
1843             if ($rc == 0) {
1844             # bail out in some manner
1845             } else {
1846             # can use Shaper
1847             }
1848              
1849             my $fontfile = '/WINDOWS/Fonts/times.ttf'; # used by both Shaper and textHS
1850             my $fontsize = 15; # used by both Shaper and textHS
1851             my $font = $pdf->ttfont($fontfile);
1852             $text->font($font, $fontsize);
1853            
1854             my $hb = HarfBuzz::Shaper->new(); # only need to set up once
1855             my %settings; # for textHS(), not Shaper
1856             $settings{'dump'} = 1; # see the diagnostics
1857             $settings{'script'} = 'Latn';
1858             $settings('dir'} = 'L'; # LTR
1859             $settings{'features'} = (); # required
1860              
1861             # -- set language (override automatic setting)
1862             #$settings{'language'} = 'en';
1863             #$hb->set_language( 'en_US' );
1864             # -- turn OFF ligatures
1865             #push @{ $settings{'features'} }, '-liga';
1866             #$hb->add_features( '-liga' );
1867             # -- turn OFF kerning
1868             #push @{ $settings{'features'} }, '-kern';
1869             #$hb->add_features( '-kern' );
1870             $hb->set_font($fontfile);
1871             $hb->set_size($fontsize);
1872             $hb->set_text("Let's eat waffles in the field for brunch.");
1873             # expect ffl and fi ligatures, and perhaps some kerning
1874              
1875             my $info = $hb->shaper();
1876             $text->textHS($info, \%settings); # -strikethru, -underline allowed
1877              
1878             The package HarfBuzz::Shaper may be optionally installed in order to use the
1879             text-shaping capabilities of the HarfBuzz library. These include kerning and
1880             ligatures in Western scripts (such as the Latin alphabet). More complex scripts
1881             can be handled, such as Arabic family and Indic scripts, where multiple forms
1882             of a character may be automatically selected, characters may be reordered, and
1883             other modifications made. The examples/HarfBuzz.pl script gives some examples
1884             of what may be done.
1885              
1886             Keep in mind that HarfBuzz works only with TrueType (.ttf) and OpenType (.otf)
1887             font files. It will not work with PostScript (Type1), core, bitmapped, or CJK
1888             fonts. Not all .ttf fonts have the instructions necessary to guide HarfBuzz,
1889             but most proper .otf fonts do. In other words, there are no guarantees that a
1890             particular font file will work with Shaper!
1891              
1892             The basic idea is to break up text into "chunks" which are of the same script
1893             (alphabet), language, direction, font face, font size, and variant (italic,
1894             bold, etc.). These could range from a single character to paragraph-length
1895             strings of text. These are fed to HarfBuzz::Shaper, along with flags, the font
1896             file to be used, and other supporting
1897             information, to create an array of output glyphs. Each element is a hash
1898             describing the glyph to be output, including its name (if available), its glyph
1899             ID (number) in the selected font, its x and y displacement (usually 0), and
1900             its "advance" x and y values, all in points. For horizontal languages (LTR and
1901             RTL), the y advance is normally 0 and the x advance is the font's character
1902             width, less any kerning amount.
1903              
1904             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
1905             can be overridden, but currently the script and text direction cannot be
1906             overridden.
1907              
1908             B the number of glyphs (array elements) may not be equal to
1909             the number of Unicode points (characters) given in the chunk's text string!
1910             Sometimes a character will be decomposed into several pieces (multiple glyphs);
1911             sometimes multiple characters may be combined into a single ligature glyph; and
1912             characters may be reordered (especially in Indic and Southeast Asian languages).
1913             As well, for Right-to-Left (bidirectional) scripts such as Hebrew and Arabic
1914             families, the text is output in Left-to-Right order (reversed from the input).
1915              
1916             With due care, a Shaper array can be manipulated in code. The elements are more
1917             or less independent of each other, so elements can be modified, rearranged,
1918             inserted, or deleted. You might adjust the position of a glyph with 'dx' and
1919             'dy' hash elements. The 'ax' value should be left alone, so that the wrong
1920             kerning isn't calculated, but you might need to adjust the "advance x" value by
1921             means of one of the following:
1922              
1923             =over
1924              
1925             =item B is a value to be I for 'ax' (points)
1926              
1927             =item B is a I value (I) of the original 'ax'
1928              
1929             =item B I 'ax' by the value (points). If negative, increase 'ax'
1930              
1931             =item B I 'ax' by the given I. Again, negative increases 'ax'
1932              
1933             =back
1934              
1935             B a given character's glyph ID is I necessarily going to be the
1936             same between any two fonts! For example, an ASCII space (U+0020) might be
1937             C0001E> in one font, and C0003E> in another font (even one
1938             closely related!). A U+00A0 required blank (non-breaking space) may be output
1939             as a regular ASCII space U+0020. Take care if you need to find a particular
1940             glyph in the array, especially if the number of elements don't match. Consider
1941             making a text string of "marker" characters (space, nbsp, hyphen, soft hyphen,
1942             etc.) and processing it through HarfBuzz::Shaper to get the corresponding
1943             glyph numbers. You may have to count spaces, say, to see where you could break
1944             a glyph array to fit a line.
1945              
1946             The C method uses the same inputs as does C.
1947             Like C, it returns the chunk length in points. Unlike
1948             C, you cannot override the glyph array's font, font size, etc.
1949              
1950             Once you have your (possibly modified) array of glyphs, you feed it to the
1951             C method to render it to the page. Remember that this method handles
1952             only a single line of text; it does not do line splitting or fitting -- that
1953             I currently need to do manually. For Western scripts (e.g., Latin), that
1954             might not be too difficult, but for other scripts that involve extensive
1955             modification of the raw characters, it may be quite difficult to split
1956             I, but you still may be able to split at inter-word spaces.
1957              
1958             A useful, but not exhaustive, set of functions are allowed by C use.
1959             Support includes direction setting (top-to-bottom and bottom-to-top directions,
1960             e.g., for Far Eastern languages in traditional orientation), and explicit
1961             script names and language (depending on what support HarfBuzz itself gives).
1962             B supported are features such as discretionary ligatures and manual
1963             selection of glyphs (e.g., swashes and alternate forms).
1964              
1965             Currently, C can only handle a single text string. We are looking at
1966             how fitting to a line length (splitting up an array) could be done, as well as
1967             how words might be split on hard and soft hyphens. At some point, full paragraph
1968             and page shaping could be possible.
1969              
1970             =cut
1971              
1972       0     sub _docs {
1973             # dummy stub
1974             }
1975              
1976             1;