.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "PDF::Builder::Docs 3pm" .TH PDF::Builder::Docs 3pm "2021-03-28" "perl v5.32.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" PDF::Builder::Docs \- additional documentation for Builder module .SH "SOME SPECIAL NOTES" .IX Header "SOME SPECIAL NOTES" .SS "Software Development Kit" .IX Subsection "Software Development Kit" There are four levels of involvement with PDF::Builder. Depending on what you want to do, different kinds of installs are recommended. .PP \&\fB1.\fR Simply installing PDF::Builder as a prerequisite for running some other package. All you need to do is install the \s-1CPAN\s0 package for PDF::Builder, and it will load the .pm files into your Perl library. If the other package prereqs PDF::Builder, its installer may download and install PDF::Builder automatically. .PP \&\fB2.\fR You want to write a Perl program that uses PDF::Builder functions. In addition to installing PDF::Builder from \s-1CPAN,\s0 you will want documentation on it. Obtain a copy of the product from GitHub (https://github.com/PhilterPaper/Perl\-PDF\-Builder) or as a gzipped tar file from \s-1CPAN.\s0 This includes a utility to build (from \s-1POD\s0) a library of \s-1HTML\s0 documents, as well as examples (examples/ directory) and contributed sample programs (contrib/ directory). .PP \&\fB3.\fR You want to modify PDF::Builder files. In addition to the \s-1CPAN\s0 and GitHub distributions, you \fImay\fR choose to keep a local Git repository for tracking your changes. Depending on whether or not your PDF::Builder copy is being used for production purposes, you may want to do your editing and testing in the Perl library installation (\fIlive\fR) or in a different place. The \*(L"t\*(R" tests (t/ directory) and examples provide good regression tests to ensure that you haven't broken anything. If you do your editing on the live code, don't forget when done to copy the changes back into the master version you keep! .PP \&\fB4.\fR You want to contribute to the development of PDF::Builder. You will need a local Git repository (and a GitHub account), so that when you've got it all done, you can issue a \*(L"Pull Request\*(R" to bring it to our attention. We can't guarantee that your work will be incorporated into the project, but at least we will look at it. From time to time, a new \s-1CPAN\s0 version will be issued. .PP If you want to make substantial changes for public use, and can't come to a meeting of minds with us, you can even start your own GitHub project and register a new \s-1CPAN\s0 project (that's what we did, \fIforking\fR \s-1PDF::API2\s0). Please don't just assume that we don't want your changes \*(-- at least propose what you want to do in writing, so we can consider it. We're always looking for people to help out and expand PDF::Builder. .SS "Optional Libraries" .IX Subsection "Optional Libraries" PDF::Builder can make use of some optional libraries, which are not \fIrequired\fR for a successful installation. If you want improved speed and capabilities for certain functions, you may want to install and use these libraries: .PP \&\fB*\fR Graphics::TIFF \*(-- PDF::Builder inherited a rather slow, buggy, and limited \&\s-1TIFF\s0 image library from \s-1PDF::API2.\s0 If Graphics::TIFF (available on \s-1CPAN,\s0 uses libtiff.a) is installed, PDF::Builder will use that instead, unless you specify that it is to use the old, pure Perl library. The only time you might want to consider this is when you need to pass an open filehandle to \f(CW\*(C`image_tiff\*(C'\fR instead of a file name. See resolved bug reports \s-1RT 84665\s0 and \s-1RT 118047,\s0 as well as \f(CW\*(C`image_tiff\*(C'\fR, for more information. .PP \&\fB*\fR Image::PNG::Libpng \*(-- PDF::Builder inherited a rather slow and buggy pure Perl \s-1PNG\s0 image library from \s-1PDF::API2.\s0 If Image::PNG::Libpng (available on \&\s-1CPAN,\s0 uses libpng.a) is installed, PDF::Builder will use that instead, unless you specify that it is to use the old, pure Perl library. Using the new library will give you improved speed, the ability to use 16 bit samples, and the ability to read interlaced \s-1PNG\s0 files. See resolved bug report \s-1RT 124349,\s0 as well as \f(CW\*(C`image_png\*(C'\fR, for more information. .PP \&\fB*\fR HarfBuzz::Shaper \*(-- This library enables PDF::Builder to handle complex scripts (Arabic, Devanagari, etc.) as well as non-LTR writing systems. It is also useful for Latin and other simple scripts, for ligatures and improved kerning. HarfBuzz::Shaper is based on a set of HarfBuzz libraries, which it will attempt to build if they are not found. See \f(CW\*(C`textHS\*(C'\fR for more information. .PP Note that the installation process \fBwill\fR attempt to install these libraries automatically. If you don't wish to use one or more of them, you are free to uninstall the optional librarie(s). If one or more failed to install, no need to panic \*(-- you simply won't be able to use some advanced features, unless you are able to manually install the modules (e.g., with \*(L"cpan install\*(R"). .SS "Strings (Character Text)" .IX Subsection "Strings (Character Text)" Perl, and hence PDF::Builder, use strings that support the full range of Unicode characters. When importing strings into a Perl program, for example by reading text from a file, you must be aware of what their character encoding is. Single-byte encodings (default is 'latin1'), represented as bytes of value 0x00 through 0xFF (0..255), will produce different results if you do something that depends on the encoding, such as sorting, searching, or comparing any two non-ASCII characters. This also applies to any characters (text) hard coded into the Perl program. .PP You can always decode the text from external encoding (\s-1ASCII, UTF\-8,\s0 Latin\-3, etc.) into the Perl (internal) \s-1UTF\-8\s0 multibyte encoding. This uses one to four bytes to represent each character. See pragma \f(CW\*(C`utf8\*(C'\fR and module \f(CW\*(C`Encode\*(C'\fR for details about decoding text. Note that only TrueType fonts (\f(CW\*(C`ttfont\*(C'\fR) can make direct use of UTF\-8\-encoded text. Other font types (core, T1, etc.) can only use single-byte encoded text. If your text is \s-1ASCII,\s0 Latin\-1, or \s-1CP\-1252,\s0 you \fIcan\fR just leave the Perl strings as the default single-byte encoding. .PP Then, there is the matter of encoding the \fIoutput\fR to match up with available font character sets. You're not actually \fItranslating\fR the text on output, but are telling the output system (and Reader) what encoding the output byte stream represents, and what character glyphs they should generate. .PP If you confine your text to plain \s-1ASCII\s0 (0x00 .. 0x7F byte values) or even Latin\-1 or \s-1CP\-1252\s0 (0x00 .. 0xFF byte values), you can use default (non\-UTF\-8) Perl strings and use the default output encoding (WinAnsiEncoding), which is more-or-less Windows \s-1CP\-1252\s0 (a superset in turn, of \s-1ISO\-8859\-1\s0 Latin\-1). If your text uses any other characters, you will need to be aware of what encoding your text strings are (in the Perl string and for declaring output glyph generation). See \*(L"Core Fonts\*(R", \*(L"\s-1PS\s0 Fonts\*(R" and \*(L"TrueType Fonts\*(R" in \*(L"\s-1FONT METHODS\*(R"\s0 for additional information. .PP \fISome Internal Details\fR .IX Subsection "Some Internal Details" .PP Some of the following may be a bit scary or confusing to beginners, so don't be afraid to skip over it until you're ready for it... .PP Perl (and PDF::Builder) internally use strings which are either single-byte (ISO\-8859\-1/Latin\-1) or multibyte \s-1UTF\-8\s0 encoded (there is an internal flag marking the string as \s-1UTF\-8\s0 or not). If you work \fIstrictly\fR in \s-1ASCII\s0 or Latin\-1 or \s-1CP\-1252\s0 (each a superset of the previous), you should be \s-1OK\s0 in not doing anything special about your string encoding. You can just use the default Perl single byte strings (internally marked as \fInot\fR \s-1UTF\-8\s0) and the default output encoding (WinAnsiEncoding). .PP If you intend to use input from a variety of sources, you should consider decoding (converting) your text to \s-1UTF\-8,\s0 which will provide an internally consistent representation (and your Perl code itself should be saved in \s-1UTF\-8,\s0 in case you want to use any hard coded non-ASCII characters). In any string, non-ASCII characters (0x80 or higher) would be converted to the Perl \s-1UTF\-8\s0 internal representation, via \f(CW\*(C`$string = Encode::decode(MY_ENCODING, $input);\*(C'\fR. \&\f(CW\*(C`MY_ENCODING\*(C'\fR would be a string like 'latin1', 'cp\-1252', 'utf8', etc. Similar capabilities are available for declaring a \fIfile\fR to be in a certain encoding. .PP Be aware that if you use \s-1UTF\-8\s0 encoding for your text, that only TrueType font output (\f(CW\*(C`ttfont\*(C'\fR) can handle it directly. Corefont and Type1 output will require that the text will have to be converted back into a single-byte encoding (using \f(CW\*(C`Encode::encode\*(C'\fR), which may need to be declared with \f(CW\*(C`\-encode\*(C'\fR (for \&\f(CW\*(C`corefont\*(C'\fR or \f(CW\*(C`psfont\*(C'\fR). If you have any characters \fInot\fR found in the selected single-byte \fIencoding\fR (but \fIare\fR found in the font itself), you will need to use \f(CW\*(C`automap\*(C'\fR to break up the font glyphs into 256 character planes, map such characters to 0x00 .. 0xFF in the appropriate plane, and switch between font planes as necessary. .PP Core and Type1 fonts (output) use the byte values in the string (single-byte encoding only!) and provide a byte-to-glyph mapping record for each plane. TrueType outputs a group of four hexadecimal digits representing the \*(L"CId\*(R" (character \s-1ID\s0) of each character. The CId does not correspond to either the single-byte or \s-1UTF\-8\s0 internal representations of the characters. .PP The bottom line is that you need to know what the internal representation of your text is, so that the output routines can tell the \s-1PDF\s0 reader about it (via the \s-1PDF\s0 file). The text will not be translated upon output, but the \s-1PDF\s0 reader needs to know what the encoding in use is, so it knows what glyph to associate with each byte (or byte sequence). .PP Note that some operating systems and Perl flavors are reputed to be strict about encoding names. For example, \fBlatin1\fR (an alias) may be rejected as invalid, while \fBiso\-8859\-1\fR (a canonical value) will work. .PP By the way, it is recommended that you be using \fIat least\fR Perl 5.10 if you are going to be using any non-ASCII characters. Perl 5.8 may be a little unpredictable in handling such text. .SS "Rendering Order" .IX Subsection "Rendering Order" For better or worse, for compatibility purposes, PDF::Builder continues the same rendering model as used by \s-1PDF::API2\s0 (and possibly its predecessors). That is, all graphics \fIfor one graphics object\fR are put into one record, and all text output \fIfor one text object\fR goes into another record. Which one is output first, is whichever is declared first. This can lead to unexpected results, where items are rendered in (apparently) the wrong order. That is, text and graphics items are not necessarily output (rendered) in the same order as they were created in code. Two items in the same object (e.g., \f(CW$text\fR) \fIwill\fR be rendered in the same order as they were coded, but items from different objects may not be rendered in the expected order. The following example (source code and annotated \s-1PDF\s0 excerpts) will hopefully illustrate the issue: .PP .Vb 3 \& use strict; \& use warnings; \& use PDF::Builder; \& \& # demonstrate text and graphics object order \& # \& my $fname = "objorder"; \& \& my $paper_size = "Letter"; \& \& # see the text and graphics stream contents \& my $pdf = PDF::Builder\->new(\-compress => \*(Aqnone\*(Aq); \& $pdf\->mediabox($paper_size); \& my $page = $pdf\->page(); \& # adjust path for your operating system \& my $fontTR = $pdf\->ttfont(\*(AqC:\e\eWindows\e\eFonts\e\etimesbd.ttf\*(Aq); .Ve .PP For the first group, you might expect the \*(L"under\*(R" line to be output, then the filled circle (disc) partly covering it, then the \*(L"over\*(R" line covering the disc, and finally a filled rectangle (bar) over both lines. What actually happened is that the \f(CW$grfx\fR graphics object was declared first, so everything in that object (the disc and bar) is output first, and the text object \f(CW$text\fR (both lines) comes afterwards. The result is that the text lines are on \fItop\fR of the graphics drawings. .PP .Vb 2 \& # \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& # 1. text, orange ball over, text over, bar over \& \& my $grfx1 = $page\->gfx(); \& my $text1 = $page\->text(); \& $text1\->font($fontTR, 20); # 20 pt Times Roman bold \& \& $text1\->fillcolor(\*(Aqblack\*(Aq); \& $grfx1\->strokecolor(\*(Aqblue\*(Aq); \& $grfx1\->fillcolor(\*(Aqorange\*(Aq); \& \& $text1\->translate(50,700); \& $text1\->text_left("This text should be under everything."); \& \& $grfx1\->circle(100,690, 30); \& $grfx1\->fillstroke(); \& \& $text1\->translate(50,670); \& $text1\->text_left("This text should be over the ball and under the bar."); \& \& $grfx1\->rect(160,660, 20,70); \& $grfx1\->fillstroke(); \& \& % \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- group 1: define graphics object first, then text \& 11 0 obj << /Length 690 >> stream % obj 11 is graphics for (1) \& 0 0 1 RG % stroke blue \& 1 0.647059 0 rg % fill orange \& 130 690 m ... c h B % draw and fill circle \& 160 660 20 70 re B % draw and fill bar \& endstream endobj \& \& 12 0 obj << /Length 438 >> stream % obj 12 is text for (1) \& BT \& /TiCBA 20 Tf % Times Roman Bold 20pt \& 0 0 0 rg % fill black \& 1 0 0 1 50 700 Tm % position text \& <0037 ... 0011> Tj % "under" line \& 1 0 0 1 50 670 Tm % position text \& <0037 ... 0011> Tj % "over" line \& ET \& endstream endobj .Ve .PP The second group is the same as the first, with the only difference being that the text object was declared first, and then the graphics object. The result is that the two text lines are rendered first, and then the disc and bar are drawn \fIover\fR them. .PP .Vb 2 \& # \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& # 2. (1) again, with graphics and text order reversed \& \& my $text2 = $page\->text(); \& my $grfx2 = $page\->gfx(); \& $text2\->font($fontTR, 20); # 20 pt Times Roman bold \& \& $text2\->fillcolor(\*(Aqblack\*(Aq); \& $grfx2\->strokecolor(\*(Aqblue\*(Aq); \& $grfx2\->fillcolor(\*(Aqorange\*(Aq); \& \& $text2\->translate(50,600); \& $text2\->text_left("This text should be under everything."); \& \& $grfx2\->circle(100,590, 30); \& $grfx2\->fillstroke(); \& \& $text2\->translate(50,570); \& $text2\->text_left("This text should be over the ball and under the bar."); \& \& $grfx2\->rect(160,560, 20,70); \& $grfx2\->fillstroke(); \& \& % \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- group 2: define text object first, then graphics \& 13 0 obj << /Length 438 >> stream % obj 13 is text for (2) \& BT \& /TiCBA 20 Tf % Times Roman Bold 20pt \& 0 0 0 rg % fill black \& 1 0 0 1 50 600 Tm % position text \& <0037 ... 0011> Tj % "under" line \& 1 0 0 1 50 570 Tm % position text \& <0037 ... 0011> Tj % "over" line \& ET \& endstream endobj \& \& 14 0 obj << /Length 690 >> stream % obj 14 is graphics for (2) \& 0 0 1 RG % stroke blue \& 1 0.647059 0 rg % fill orange \& 130 590 m ... h B % draw and fill circle \& 160 560 20 70 re B % draw and fill bar \& endstream endobj .Ve .PP The third group defines two text and two graphics objects, in the order that they are expected in. The \*(L"under\*(R" text line is output first, then the orange disc graphics is output, partly covering the text. The \*(L"over\*(R" text line is now output \*(-- it's actually \fIover\fR the disc, but is orange because the previous object stream (first graphics object) left the fill color (also used for text) as orange, because we didn't explicitly set the fill color before outputting the second text line. This is not \*(L"inheritance\*(R" so much as it is whatever the graphics (drawing) state (used for both \*(L"graphics\*(R" and \*(L"text\*(R") is left in at the end of one object, it's the state at the beginning of the next object. If you wish to control this, consider surrounding the graphics or text calls with \f(CW\*(C`save()\*(C'\fR and \f(CW\*(C`restore()\*(C'\fR calls to save and restore (push and pop) the graphics state to what it was at the \f(CW\*(C`save()\*(C'\fR. Finally, the bar is drawn over everything. .PP .Vb 2 \& # \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& # 3. (2) again, with two graphics and two text objects \& \& my $text3 = $page\->text(); \& my $grfx3 = $page\->gfx(); \& $text3\->font($fontTR, 20); # 20 pt Times Roman bold \& my $text4 = $page\->text(); \& my $grfx4 = $page\->gfx(); \& $text4\->font($fontTR, 20); # 20 pt Times Roman bold \& \& $text3\->fillcolor(\*(Aqblack\*(Aq); \& $grfx3\->strokecolor(\*(Aqblue\*(Aq); \& $grfx3\->fillcolor(\*(Aqorange\*(Aq); \& # $text4\->fillcolor(\*(Aqyellow\*(Aq); \& # $grfx4\->strokecolor(\*(Aqred\*(Aq); \& # $grfx4\->fillcolor(\*(Aqpurple\*(Aq); \& \& $text3\->translate(50,500); \& $text3\->text_left("This text should be under everything."); \& \& $grfx3\->circle(100,490, 30); \& $grfx3\->fillstroke(); \& \& $text4\->translate(50,470); \& $text4\->text_left("This text should be over the ball and under the bar."); \& \& $grfx4\->rect(160,460, 20,70); \& $grfx4\->fillstroke(); \& \& % \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- group 3: define text1, graphics1, text2, graphics2 \& 15 0 obj << /Length 206 >> stream % obj 15 is text1 for (3) \& BT \& /TiCBA 20 Tf % Times Roman Bold 20pt \& 0 0 0 rg % fill black \& 1 0 0 1 50 500 Tm % position text \& <0037 ... 0011> Tj % "under" line \& ET \& endstream endobj \& \& 16 0 obj << /Length 671 >> stream % obj 16 is graphics1 for (3) circle \& 0 0 1 RG % stroke blue \& 1 0.647059 0 rg % fill orange \& 130 490 m ... h B % draw and fill circle \& endstream endobj \& \& 17 0 obj << /Length 257 >> stream % obj 17 is text2 for (3) \& BT \& /TiCBA 20 Tf % Times Roman Bold 20pt \& 1 0 0 1 50 470 Tm % position text \& <0037 ... 0011> Tj % "over" line \& ET \& endstream endobj \& \& 18 0 obj << /Length 20 >> stream % obj 18 is graphics for (3) bar \& 160 460 20 70 re B % draw and fill bar \& endstream endobj .Ve .PP The fourth group is the same as the third, except that we define the fill color for the text in the second line. This makes it clear that the \*(L"over\*(R" line (in yellow) was written \fIafter\fR the orange disc, and still before the bar. .PP .Vb 2 \& # \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& # 4. (3) again, a new set of colors for second group \& \& my $text3 = $page\->text(); \& my $grfx3 = $page\->gfx(); \& $text3\->font($fontTR, 20); # 20 pt Times Roman bold \& my $text4 = $page\->text(); \& my $grfx4 = $page\->gfx(); \& $text4\->font($fontTR, 20); # 20 pt Times Roman bold \& \& $text3\->fillcolor(\*(Aqblack\*(Aq); \& $grfx3\->strokecolor(\*(Aqblue\*(Aq); \& $grfx3\->fillcolor(\*(Aqorange\*(Aq); \& $text4\->fillcolor(\*(Aqyellow\*(Aq); \& $grfx4\->strokecolor(\*(Aqred\*(Aq); \& $grfx4\->fillcolor(\*(Aqpurple\*(Aq); \& \& $text3\->translate(50,400); \& $text3\->text_left("This text should be under everything."); \& \& $grfx3\->circle(100,390, 30); \& $grfx3\->fillstroke(); \& \& $text4\->translate(50,370); \& $text4\->text_left("This text should be over the ball and under the bar."); \& \& $grfx4\->rect(160,360, 20,70); \& $grfx4\->fillstroke(); \& \& % \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- group 4: define text1, graphics1, text2, graphics2 with colors for 2 \& 19 0 obj << /Length 206 >> stream % obj 19 is text1 for (4) \& BT \& /TiCBA 20 Tf % Times Roman Bold 20pt \& 0 0 0 rg % fill black \& 1 0 0 1 50 400 Tm % position text \& <0037 ... 0011> Tj % "under" line \& ET \& endstream endobj \& \& 20 0 obj << /Length 671 >> stream % obj 20 is graphics1 for (4) circle \& 0 0 1 RG % stroke blue \& 1 0.647059 0 rg % fill orange \& 130 390 m ... h B % draw and fill circle \& endstream endobj \& \& 21 0 obj << /Length 266 >> stream % obj 21 is text2 for (4) \& BT \& /TiCBA 20 Tf % Times Roman Bold 20pt \& 1 1 0 rg % fill yellow \& 1 0 0 1 50 370 Tm % position text \& <0037 ... 0011> Tj % "over" line \& ET \& endstream endobj \& \& 22 0 obj << /Length 52 >> stream % obj 22 is graphics for (4) bar \& 1 0 0 RG % stroke red \& 0.498039 0 0.498039 rg % fill purple \& 160 360 20 70 re B % draw and fill rectangle (bar) \& endstream endobj \& \& # \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- \& $pdf\->saveas("$fname.pdf"); .Ve .PP The separation of text and graphics means that only some text methods are available in a graphics object, and only some graphics methods are available in a text object. There is much overlap, but they differ. There's really no reason the code couldn't have been written (in \s-1PDF::API2,\s0 or earlier) as outputting to a single object, which would keep everything in the same order as the method calls. An advantage would be less object and stream overhead in the \&\s-1PDF\s0 file. The only drawback might be that an object might more easily overflow and require splitting into multiple objects, but that should be rare. .PP You should always be able to manually split an object by simply ending output to the first object, and picking up with output to the second object, \fIso long as it was created immediately after the first object.\fR The graphics state at the end of the first object should be the initial state at the beginning of the second object. \fBHowever,\fR use caution when dealing with text objects \*(-- the \&\s-1PDF\s0 specification states that the Text matrices are \fInot\fR carried over from one object to the next (\fB\s-1BT\s0\fR resets them), so you may need to reset some settings. .PP .Vb 4 \& $grfx1 = $page\->gfx(); \& $grfx2 = $page\->gfx(); \& # write a huge amount of stuff to $grfx1 \& # write a huge amount of stuff to $grfx2, picking up where $grfx1 left off .Ve .PP In any case, now that you understand the rendering order and how the order of object declarations affects it, how text and graphics are drawn can now be completely controlled as desired. There is really no need to add another \*(L"both\*(R" type object that will handle all graphics and text objects, as that would probably be a major code bloat for very little benefit. However, it could be considered in the future if there is a demonstrated need for it, such as serious \s-1PDF\s0 file size bloat due to the extra object overhead when interleaving text and graphics output. .SS "\s-1PDF\s0 Versions Supported" .IX Subsection "PDF Versions Supported" When creating a \s-1PDF\s0 file using the functions in PDF::Builder, the output is marked as \s-1PDF 1.4.\s0 This does not mean that all \fI\s-1PDF\s0\fR functionality up through 1.4 is supported! There are almost surely features missing as far back as the \&\s-1PDF 1.0\s0 standard. .PP The big problem is when a \s-1PDF\s0 of version 1.5 or higher is imported or opened in PDF::Builder. If it contains content that is actually unsupported by this software, there is a chance that something will break. This does not guarantee that a \s-1PDF\s0 marked as \*(L"1.7\*(R" will go down in flames when read by PDF::Builder, or that a \s-1PDF\s0 written back out will break in a Reader, but the possibility is there. Much \s-1PDF\s0 writer software simply marks its output as the highest version of \s-1PDF\s0 at the time (usually 1.7), even if there is no content beyond, say, 1.2. There is \fIsome\fR handling of \s-1PDF 1.5\s0 items in PDF::Builder, such as cross reference streams, but support beyond 1.4 is very limited. All we can say is to be careful when handling PDFs whose version is above 1.4, and test thoroughly, as they may break at some point. .PP PDF::Builder includes a simple version control mechanism, where the initial \&\s-1PDF\s0 version to be output (default 1.4) can be set by the programmer. Input PDFs greater than 1.4 (current output level) will receive a warning (can be suppressed) that the output level will be raised to that level. The use of \s-1PDF\s0 features greater than the current output level will likewise trigger a warning that the output level is to be raised to the necessary level. If this is not desired, you should avoid using those \s-1PDF\s0 features which are higher than the desired \s-1PDF\s0 output level. .SS "History" .IX Subsection "History" \&\s-1PDF::API2\s0 was originally written by Alfred Reibenschuh, derived from Martin Hosken's Text::PDF via the Text::PDF::API wrapper. In 2009, Otto Hirr started the \s-1PDF::API3\s0 fork, but it never went anywhere. In 2011, \s-1PDF::API2\s0 maintenance was taken over by Steve Simms. In 2017, PDF::Builder was forked by Phil M. Perry, who desired a more aggressive schedule of new features and bug fixes than Simms was providing. .PP At Simms's request, the name of the new offering was changed from \s-1PDF::API4\s0 to PDF::Builder, to reduce the chance of confusion due to parallel development. Perry's intent is to keep all internal methods as upwardly compatible with \&\s-1PDF::API2\s0 as possible, although it is likely that there will be some drift (incompatibilities) over time. At least initially, any program written based on \&\s-1PDF::API2\s0 should be convertible to PDF::Builder simply by changing \*(L"\s-1API2\*(R"\s0 anywhere it occurs to \*(L"Builder\*(R". See the \s-1INFO/KNOWN_INCOMP\s0 known incompatibilities file for further information. .SH "DETAILED NOTES ON METHODS" .IX Header "DETAILED NOTES ON METHODS" .SS "After saving a file..." .IX Subsection "After saving a file..." Note that a \s-1PDF\s0 object such as \f(CW$pdf\fR cannot continue to be used after saving an output \s-1PDF\s0 file or string with \f(CW$pdf\fR\->\f(CW\*(C`save()\*(C'\fR, \f(CW\*(C`saveas()\*(C'\fR, or \&\f(CW\*(C`stringify()\*(C'\fR. There is some cleanup and other operations done internally which make the object unusable for further operations. You will likely receive an error message about \fBcan't call method new_obj on an undefined value\fR if you try to keep using a \s-1PDF\s0 object. .SS "IntegrityCheck" .IX Subsection "IntegrityCheck" The PDF::Builder methods that open an existing \s-1PDF\s0 file, pass it by the integrity checker method, \f(CW\*(C`$self\->IntegrityCheck(level, content)\*(C'\fR. This method servers two purposes: 1) to find any \f(CW\*(C`/Version\*(C'\fR settings that override the \&\s-1PDF\s0 version found in the \s-1PDF\s0 heading, and 2) perform some basic validations on the contents of the \s-1PDF.\s0 .PP The \f(CW\*(C`level\*(C'\fR parameter accepts the following values: .IP "0 = Do not output any diagnostic messages; just return any version override." 4 .IX Item "0 = Do not output any diagnostic messages; just return any version override." .PD 0 .IP "1 = Output error-level (serious) diagnostic messages, as well as returning any version override." 4 .IX Item "1 = Output error-level (serious) diagnostic messages, as well as returning any version override." .PD 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. .IP "2 = Output error\- (serious) and warning\- (less serious) level diagnostic messages, as well as returning any version override. \fBThis is the default.\fR" 4 .IX Item "2 = Output error- (serious) and warning- (less serious) level diagnostic messages, as well as returning any version override. This is the default." .PD 0 .IP "3 = Output error\- (serious), warning\- (less serious), and note\- (informational) level diagnostic messages, as well as returning any version override." 4 .IX Item "3 = Output error- (serious), warning- (less serious), and note- (informational) level diagnostic messages, as well as returning any version override." .PD 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 \s-1OK\s0 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. .IP "4 = Output error\-, warning\-, and note-level diagnostic messages, as well as returning any version override. Also dump the diagnostic data structure." 4 .IX Item "4 = Output error-, warning-, and note-level diagnostic messages, as well as returning any version override. Also dump the diagnostic data structure." .PD 0 .ie n .IP "5 = Output error\-, warning\-, and note-level diagnostic messages, as well as returning any version override. Also dump the diagnostic data structure and the $self data structure (generally useful only if you have already read in the \s-1PDF\s0 file)." 4 .el .IP "5 = Output error\-, warning\-, and note-level diagnostic messages, as well as returning any version override. Also dump the diagnostic data structure and the \f(CW$self\fR data structure (generally useful only if you have already read in the \s-1PDF\s0 file)." 4 .IX 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 $self data structure (generally useful only if you have already read in the PDF file)." .PD .PP The version is a string (e.g., '1.5') if found, otherwise \f(CW\*(C`undef\*(C'\fR (undefined value) is returned. .PP For controlling the \*(L"automatic\*(R" call to IntegrityCheck (via opens), the level may be given with the option (flag) \f(CW\*(C`\-diaglevel => \f(CIn\f(CW\*(C'\fR, where \f(CW\*(C`n\*(C'\fR is between 0 and 5. .SS "Preferences \- set user display preferences" .IX Subsection "Preferences - set user display preferences" .ie n .IP "$pdf\->preferences(%options)" 4 .el .IP "\f(CW$pdf\fR\->preferences(%options)" 4 .IX Item "$pdf->preferences(%options)" Controls viewing preferences for the \s-1PDF.\s0 .PP \fIPage Mode Options\fR .IX Subsection "Page Mode Options" .RS 4 .IP "\-fullscreen" 4 .IX Item "-fullscreen" Full-screen mode, with no menu bar, window controls, or any other window visible. .IP "\-thumbs" 4 .IX Item "-thumbs" Thumbnail images visible. .IP "\-outlines" 4 .IX Item "-outlines" Document outline visible. .RE .RS 4 .RE .PP \fIPage Layout Options\fR .IX Subsection "Page Layout Options" .RS 4 .IP "\-singlepage" 4 .IX Item "-singlepage" Display one page at a time. .IP "\-onecolumn" 4 .IX Item "-onecolumn" Display the pages in one column. .IP "\-twocolumnleft" 4 .IX Item "-twocolumnleft" Display the pages in two columns, with oddnumbered pages on the left. .IP "\-twocolumnright" 4 .IX Item "-twocolumnright" Display the pages in two columns, with oddnumbered pages on the right. .RE .RS 4 .RE .PP \fIViewer Options\fR .IX Subsection "Viewer Options" .RS 4 .IP "\-hidetoolbar" 4 .IX Item "-hidetoolbar" Specifying whether to hide tool bars. .IP "\-hidemenubar" 4 .IX Item "-hidemenubar" Specifying whether to hide menu bars. .IP "\-hidewindowui" 4 .IX Item "-hidewindowui" Specifying whether to hide user interface elements. .IP "\-fitwindow" 4 .IX Item "-fitwindow" Specifying whether to resize the document's window to the size of the displayed page. .IP "\-centerwindow" 4 .IX Item "-centerwindow" Specifying whether to position the document's window in the center of the screen. .IP "\-displaytitle" 4 .IX Item "-displaytitle" Specifying whether the window's title bar should display the document title taken from the Title entry of the document information dictionary. .IP "\-afterfullscreenthumbs" 4 .IX Item "-afterfullscreenthumbs" Thumbnail images visible after Full-screen mode. .IP "\-afterfullscreenoutlines" 4 .IX Item "-afterfullscreenoutlines" Document outline visible after Full-screen mode. .IP "\-printscalingnone" 4 .IX Item "-printscalingnone" Set the default print setting for page scaling to none. .IP "\-simplex" 4 .IX Item "-simplex" Print single-sided by default. .IP "\-duplexflipshortedge" 4 .IX Item "-duplexflipshortedge" Print duplex by default and flip on the short edge of the sheet. .IP "\-duplexfliplongedge" 4 .IX Item "-duplexfliplongedge" Print duplex by default and flip on the long edge of the sheet. .RE .RS 4 .RE .PP \fIInitial Page Options\fR .IX Subsection "Initial Page Options" .ie n .IP "\-firstpage => [ $page, %options ]" 4 .el .IP "\-firstpage => [ \f(CW$page\fR, \f(CW%options\fR ]" 4 .IX Item "-firstpage => [ $page, %options ]" Specifying the page (either a page number or a page object) to be displayed, plus one of the following options: .RS 4 .IP "\-fit => 1" 4 .IX Item "-fit => 1" Display the page designated by page, with its contents magnified just enough to fit the entire page within the window both horizontally and vertically. If the required horizontal and vertical magnification factors are different, use the smaller of the two, centering the page within the window in the other dimension. .ie n .IP "\-fith => $top" 4 .el .IP "\-fith => \f(CW$top\fR" 4 .IX Item "-fith => $top" Display the page designated by page, with the vertical coordinate top positioned at the top edge of the window and the contents of the page magnified just enough to fit the entire width of the page within the window. .ie n .IP "\-fitv => $left" 4 .el .IP "\-fitv => \f(CW$left\fR" 4 .IX Item "-fitv => $left" Display the page designated by page, with the horizontal coordinate left positioned at the left edge of the window and the contents of the page magnified just enough to fit the entire height of the page within the window. .ie n .IP "\-fitr => [ $left, $bottom, $right, $top ]" 4 .el .IP "\-fitr => [ \f(CW$left\fR, \f(CW$bottom\fR, \f(CW$right\fR, \f(CW$top\fR ]" 4 .IX Item "-fitr => [ $left, $bottom, $right, $top ]" Display the page designated by page, with its contents magnified just enough to fit the rectangle specified by the coordinates left, bottom, right, and top entirely within the window both horizontally and vertically. If the required horizontal and vertical magnification factors are different, use the smaller of the two, centering the rectangle within the window in the other dimension. .IP "\-fitb => 1" 4 .IX Item "-fitb => 1" Display the page designated by page, with its contents magnified just enough to fit its bounding box entirely within the window both horizontally and vertically. If the required horizontal and vertical magnification factors are different, use the smaller of the two, centering the bounding box within the window in the other dimension. .ie n .IP "\-fitbh => $top" 4 .el .IP "\-fitbh => \f(CW$top\fR" 4 .IX Item "-fitbh => $top" Display the page designated by page, with the vertical coordinate top positioned at the top edge of the window and the contents of the page magnified just enough to fit the entire width of its bounding box within the window. .ie n .IP "\-fitbv => $left" 4 .el .IP "\-fitbv => \f(CW$left\fR" 4 .IX Item "-fitbv => $left" Display the page designated by page, with the horizontal coordinate left positioned at the left edge of the window and the contents of the page magnified just enough to fit the entire height of its bounding box within the window. .ie n .IP "\-xyz => [ $left, $top, $zoom ]" 4 .el .IP "\-xyz => [ \f(CW$left\fR, \f(CW$top\fR, \f(CW$zoom\fR ]" 4 .IX Item "-xyz => [ $left, $top, $zoom ]" Display the page designated by page, with the coordinates (left, top) positioned at the top-left corner of the window and the contents of the page magnified by the factor zoom. A zero (0) value for any of the parameters left, top, or zoom specifies that the current value of that parameter is to be retained unchanged. .RE .RS 4 .RE .PP \fIExample\fR .IX Subsection "Example" .PP .Vb 6 \& $pdf\->preferences( \& \-fullscreen => 1, \& \-onecolumn => 1, \& \-afterfullscreenoutlines => 1, \& \-firstpage => [$page, \-fit => 1], \& ); .Ve .SS "info Example" .IX Subsection "info Example" .Vb 11 \& %h = $pdf\->info( \& \*(AqAuthor\*(Aq => "Alfred Reibenschuh", \& \*(AqCreationDate\*(Aq => "D:20020911000000+01\*(Aq00\*(Aq", \& \*(AqModDate\*(Aq => "D:YYYYMMDDhhmmssOHH\*(Aqmm\*(Aq", \& \*(AqCreator\*(Aq => "fredos\-script.pl", \& \*(AqProducer\*(Aq => "PDF::Builder", \& \*(AqTitle\*(Aq => "some Publication", \& \*(AqSubject\*(Aq => "perl ?", \& \*(AqKeywords\*(Aq => "all good things are pdf" \& ); \& print "Author: $h{\*(AqAuthor\*(Aq}\en"; .Ve .SS "\s-1XMP XML\s0 example" .IX Subsection "XMP XML example" .Vb 10 \& $xml = $pdf\->xmpMetadata(); \& print "PDFs Metadata reads: $xml\en"; \& $xml=< \& \& \& \& \& \& \& \& \& \& Adobe Portable Document Format (PDF) \& \& \& \& \& Adobe Systems Incorporated \& \& \& \& \& PDF Reference, version 1.6 \& \& \& \& \& \& \& EOT \& \& $xml = $pdf\->xmpMetadata($xml); \& print "PDF metadata now reads: $xml\en"; .Ve .ie n .SS """\s-1BOX"" METHODS\s0" .el .SS "``\s-1BOX'' METHODS\s0" .IX Subsection "BOX METHODS" \&\fBA general note:\fR Use care if specifying a different Media Box (or other \*(L"box\*(R") for a page, than the global \*(L"box\*(R" setting, to define the whole \*(L"chain\*(R" of boxes on the page, to avoid surprises. For example, to define a global Media Box (paper size) and a global Crop Box, and then define a new page-level Media Box \&\fIwithout\fR defining a new page-level Crop Box, may give odd results in the resultant cropping. Such combinations are not well defined. .PP All dimensions in boxes default to the default User Unit, which is points (1/72 inch). Note that the \s-1PDF\s0 specification limits sizes and coordinates to 14400 User Units (200 inches, for the default User Unit of one point), and Adobe products (so far) follow this limit for Acrobat and Distiller. It is worth noting that other \s-1PDF\s0 writers and readers may choose to ignore the 14400 unit limit, with or without the use of a specified User Unit. Therefore, PDF::Builder does not enforce any limits on coordinates \*(-- it's \fIyour\fR responsibility to consider what readers and other \s-1PDF\s0 tools may be used with a \s-1PDF\s0 you produce! Also note that earlier Acrobat readers had coordinate limits as small as 3240 User Units (45 inches), and \fIminimum\fR media size of 72 or 3 User Units. .PP \fIUser Units\fR .IX Subsection "User Units" .ie n .IP "$pdf\->userunit($number)" 4 .el .IP "\f(CW$pdf\fR\->userunit($number)" 4 .IX Item "$pdf->userunit($number)" The default User Unit in the \s-1PDF\s0 coordinate system is one point (1/72 inch). You can think of it as a scale factor to enable larger (or even, smaller) documents. This method may be used (for \s-1PDF 1.6\s0 and higher) to set the User Unit to some number of points. For example, \f(CW\*(C`userunit(72)\*(C'\fR will set the scale multiplier to 72.0 points per User Unit, or 1 inch to the User Unit. Any number greater than zero is acceptable, although some readers and tools may not handle User Units of less than 1.0 very well. .Sp Not all readers respect the User Unit, if you give one, or handle it in exactly the same way. Adobe Distiller, for one, does not use it. How User Units are handled may vary from reader to reader. Adobe Acrobat, at this writing, respects User Unit in version 7.0 and up, but limits it to 75000 (giving a maximum document size of 15 million inches or 236.7 miles or 381 km). Other readers and \&\s-1PDF\s0 tools may allow a larger (or smaller) limit. .Sp \&\fBYour Mileage May Vary:\fR Some readers ignore a global User Unit setting and do \fInot\fR have pages inherit it (PDF::Builder duplicates it on each page to simulate inheritance). Some readers may give spurious warnings about truncated content when a Media Box is changed while User Units are being used. Some readers do strange things with Crop Boxes when a User Unit is in effect. .Sp Depending on the reader used, the effect of a larger User Unit (greater than 1) may mean lower resolution (chunkier or coarser appearance) in the rendered document. If you're printing something the size of a highway billboard, this may not matter to you, but you should be aware of the possibility (even with fractional coordinates). Conversely, a User Unit of less than 1.0 (if permitted) reduces the allowable size of your document, but \fImay\fR result in greater resolution. .Sp A global (\s-1PDF\s0 level) User Unit setting is inherited by each page (an action by PDF::Builder, not necessarily automatically done by the reader), or can be overridden by calling userunit in the page. Do not give more than one global userunit setting, as only the last one will be used. Setting a page's User Unit (if \f(CW\*(C`$page\->\*(C'\fR instead) is permitted (overriding the global setting for this page). However, many sources recommend against doing this, as results may not be as expected (once again, depending on the quirks of the reader). .Sp Remember to call \f(CW\*(C`userunit\*(C'\fR \fIbefore\fR calling anything having to do with page or box sizes, or coordinates. Especially when setting 'named' box sizes, the methods need to know the current User Unit so that named page sizes (in points) may be scaled down to the current User Unit. .PP \fIMedia Box\fR .IX Subsection "Media Box" .ie n .IP "$pdf\->mediabox($name)" 4 .el .IP "\f(CW$pdf\fR\->mediabox($name)" 4 .IX Item "$pdf->mediabox($name)" .PD 0 .ie n .IP "$pdf\->mediabox($name, \-orient => 'orientation' )" 4 .el .IP "\f(CW$pdf\fR\->mediabox($name, \-orient => 'orientation' )" 4 .IX Item "$pdf->mediabox($name, -orient => 'orientation' )" .ie n .IP "$pdf\->mediabox($w,$h)" 4 .el .IP "\f(CW$pdf\fR\->mediabox($w,$h)" 4 .IX Item "$pdf->mediabox($w,$h)" .ie n .IP "$pdf\->mediabox($llx,$lly, $urx,$ury)" 4 .el .IP "\f(CW$pdf\fR\->mediabox($llx,$lly, \f(CW$urx\fR,$ury)" 4 .IX Item "$pdf->mediabox($llx,$lly, $urx,$ury)" .ie n .IP "($llx,$lly, $urx,$ury) = $pdf\->\fBmediabox()\fR" 4 .el .IP "($llx,$lly, \f(CW$urx\fR,$ury) = \f(CW$pdf\fR\->\fBmediabox()\fR" 4 .IX Item "($llx,$lly, $urx,$ury) = $pdf->mediabox()" .PD Sets the global Media Box (or page's Media Box, if \f(CW\*(C`$page\->\*(C'\fR instead). This defines the width and height (or by corner coordinates, or by standard name) of the output page itself, such as the physical paper size. This is normally the largest of the \*(L"boxes\*(R". If any subsidiary box (within it) exceeds the media box, the portion of the material or boxes outside of the Media Box will be ignored. That is, the Media Box is the One Box to Rule Them All, and is the overall limit for other boxes (some documentation refers to the Media Box as \*(L"clipping\*(R" other boxes). In addition, the Media Box defines the overall \fIcoordinate system\fR for text and graphics operations. .Sp If no arguments are given, the current Media Box (global or page) coordinates are returned instead. The former \f(CW\*(C`get_mediabox\*(C'\fR (page only) function is \&\fBdeprecated\fR and will likely be removed some time in the future. In addition, when \fIsetting\fR the Media Box, the resulting coordinates are returned. This permits you to specify the page size by a name (alias) and get the dimensions back, all in one call. .Sp Note that many printers can \fBnot\fR print all the way to the physical edge of the paper, so you should plan to leave some blank margin, even outside of any crop marks and bleeds. Printers and on-screen readers are free to discard any content found outside the Media Box, and printers may discard some material just inside the Media Box. .Sp A \fIglobal\fR Media Box is \fBrequired\fR by the \s-1PDF\s0 spec; if not explicitly given, PDF::Builder will set the global Media Box to \s-1US\s0 Letter size (8.5in x 11in). This is the media size that will be used for all pages if you do not specify a \f(CW\*(C`mediabox\*(C'\fR call on a page. That is, a global (\s-1PDF\s0 level) mediabox setting is inherited by each page, or can be overridden by setting mediabox in the page. Do not give more than one global mediabox setting, as only the last one will be used. .Sp If you give a single string name (e.g., 'A4'), you may optionally add an orientation to turn the page 90 degrees into Landscape mode: \&\f(CW\*(C`\-orient => \*(AqL\*(Aq\*(C'\fR or \f(CW\*(C`\-orient => \*(Aql\*(Aq\*(C'\fR. \f(CW\*(C`\-orient\*(C'\fR is the only option recognized, and a string beginning with an 'L' or 'l' (for Landscape) is the only value of interest (anything else is treated as Portrait mode). The \fIy\fR axis still runs from 0 at the bottom of the page to what used to be the page \&\fIwidth\fR (now, \fIheight\fR) at the top, and likewise for the \fIx\fR axis: 0 at left to (former) \fIheight\fR at the right. That is, the coordinate system is the same as before, except that the height and width are different. .Sp The lower left corner does not \fIhave\fR to be 0,0. It can be any values you want, including negative values (so long as the resulting media's sides are at least one point long). \f(CW\*(C`mediabox\*(C'\fR sets the coordinate system (including the origin) of the graphics and text that will be drawn, as well as for subsequent \*(L"boxes\*(R". It's even possible to give any two opposite corners (such as upper left and lower right). The coordinate system will be rearranged (by the Reader) to still be the conventional minimum \f(CW\*(C`x\*(C'\fR and \f(CW\*(C`y\*(C'\fR in the lower left (i.e., you can't make \f(CW\*(C`y\*(C'\fR \fIincrease\fR from top to bottom!). .Sp \&\fBExample:\fR .Sp .Vb 4 \& $pdf = PDF::Builder\->new(); \& $pdf\->mediabox(\*(AqA4\*(Aq); # A4 size (595 Pt wide by 842 Pt high) \& ... \& $pdf\->saveas(\*(Aqour/new.pdf\*(Aq); \& \& $pdf = PDF::Builder\->new(); \& $pdf\->mediabox(595, 842); # A4 size, with implicit 0,0 LL corner \& ... \& $pdf\->saveas(\*(Aqour/new.pdf\*(Aq); \& \& $pdf = PDF::Builder\->new; \& $pdf\->mediabox(0, 0, 595, 842); # A4 size, with explicit 0,0 LL corner \& ... \& $pdf\->saveas(\*(Aqour/new.pdf\*(Aq); .Ve .Sp See the PDF::Builder::Resource::PaperSizes source code for the full list of supported names (aliases) and their dimensions in points. You are free to add additional paper sizes to this file, if you wish. You might want to do this if you frequently use a standard page size in rotated (Landscape) mode. See also the \f(CW\*(C`getPaperSizes\*(C'\fR call in PDF::Builder::Util. These names (aliases) are also usable in other \*(L"box\*(R" calls, although useful only if the \*(L"box\*(R" is the same size as the full media (Media Box), and you don't mind their starting at 0,0. .PP \fICrop Box\fR .IX Subsection "Crop Box" .ie n .IP "$pdf\->cropbox($name)" 4 .el .IP "\f(CW$pdf\fR\->cropbox($name)" 4 .IX Item "$pdf->cropbox($name)" .PD 0 .ie n .IP "$pdf\->cropbox($name, \-orient => 'orientation')" 4 .el .IP "\f(CW$pdf\fR\->cropbox($name, \-orient => 'orientation')" 4 .IX Item "$pdf->cropbox($name, -orient => 'orientation')" .ie n .IP "$pdf\->cropbox($w,$h)" 4 .el .IP "\f(CW$pdf\fR\->cropbox($w,$h)" 4 .IX Item "$pdf->cropbox($w,$h)" .ie n .IP "$pdf\->cropbox($llx,$lly, $urx,$ury)" 4 .el .IP "\f(CW$pdf\fR\->cropbox($llx,$lly, \f(CW$urx\fR,$ury)" 4 .IX Item "$pdf->cropbox($llx,$lly, $urx,$ury)" .ie n .IP "($llx,$lly, $urx,$ury) = $pdf\->\fBcropbox()\fR" 4 .el .IP "($llx,$lly, \f(CW$urx\fR,$ury) = \f(CW$pdf\fR\->\fBcropbox()\fR" 4 .IX Item "($llx,$lly, $urx,$ury) = $pdf->cropbox()" .PD Sets the global Crop Box (or page's Crop Box, if \f(CW\*(C`$page\->\*(C'\fR instead). This will define the media size to which the output will later be \fIclipped\fR. Note that this does \fBnot\fR itself output any crop marks to guide cutting of the paper! \s-1PDF\s0 Readers should consider this to be the \&\fIvisible\fR portion of the page, and anything found outside it \fImay\fR be clipped (invisible). By default, it is equal to the Media Box, but may be defined to be smaller, in the coordinate system set by the Media Box. A global setting will be inherited by each page, but can be overridden on a per-page basis. .Sp A Reader or Printer may choose to discard any clipped (invisible) part of the page, and show only the area \fIwithin\fR the Crop Box. For example, if your page Media Box is A4 (0,0 to 595,842 Points), and your Crop Box is (100,100 to 495,742), a reader such as Adobe Acrobat Reader may show you a page 395 by 642 Points in size (i.e., just the visible area of your page). Other Readers may show you the full media size (Media Box) and a 100 Point wide blank area (in this example) around the visible content. .Sp If no arguments are given, the current Crop Box (global or page) coordinates are returned instead. The former \f(CW\*(C`get_cropbox\*(C'\fR (page only) function is \&\fBdeprecated\fR and will likely be removed some time in the future. If a Crop Box has not been defined, the Media Box coordinates (which always exist) will be returned instead. In addition, when \fIsetting\fR the Crop Box, the resulting coordinates are returned. This permits you to specify the crop box by a name (alias) and get the dimensions back, all in one call. .Sp Do not confuse the Crop Box with the \f(CW\*(C`Trim Box\*(C'\fR, which shows where printed paper is expected to actually be \fIcut\fR. Some \s-1PDF\s0 Readers may reduce the visible \*(L"paper\*(R" background to the size of the crop box; others may simply omit any content outside it. Either way, you would lose any trim or crop marks, printer instructions, color alignment dots, or other content outside the Crop Box. \fIA good use of the Crop Box\fR would be limit printing to the area where a printer \fIcan\fR reliably put down ink, and leave white the edge areas where paper-handling mechanisms prevent ink or toner from being applied. This would keep you from accidentally putting valuable content in an area where a printer will refuse to print, yet permit you to include a bleed area and space for printer's marks and instructions. Needless to say, if your printer cannot print to the very edge of the paper, you will need to trim (cut) the printed sheets to get true bleeds. .Sp A global (\s-1PDF\s0 level) cropbox setting is inherited by each page, or can be overridden by setting cropbox in the page. As with \f(CW\*(C`mediabox\*(C'\fR, only one crop box may be set at this (\s-1PDF\s0) level. As with \f(CW\*(C`mediabox\*(C'\fR, a named media size may have an orientation (l or L) for Landscape mode. Note that the \s-1PDF\s0 level global Crop Box will be used \fIeven if\fR the page gets its own Media Box. That is, the page's Crop Box inherits the global Crop Box, not the page Media Box, even if the page has its own media size! If you set the page's own Media Box, you should consider also explicitly setting the page Crop Box (and other boxes). .PP \fIBleed Box\fR .IX Subsection "Bleed Box" .ie n .IP "$pdf\->bleedbox($name)" 4 .el .IP "\f(CW$pdf\fR\->bleedbox($name)" 4 .IX Item "$pdf->bleedbox($name)" .PD 0 .ie n .IP "$pdf\->bleedbox($name, \-orient => 'orientation')" 4 .el .IP "\f(CW$pdf\fR\->bleedbox($name, \-orient => 'orientation')" 4 .IX Item "$pdf->bleedbox($name, -orient => 'orientation')" .ie n .IP "$pdf\->bleedbox($w,$h)" 4 .el .IP "\f(CW$pdf\fR\->bleedbox($w,$h)" 4 .IX Item "$pdf->bleedbox($w,$h)" .ie n .IP "$pdf\->bleedbox($llx,$lly, $urx,$ury)" 4 .el .IP "\f(CW$pdf\fR\->bleedbox($llx,$lly, \f(CW$urx\fR,$ury)" 4 .IX Item "$pdf->bleedbox($llx,$lly, $urx,$ury)" .ie n .IP "($llx,$lly, $urx,$ury) = $pdf\->\fBbleedbox()\fR" 4 .el .IP "($llx,$lly, \f(CW$urx\fR,$ury) = \f(CW$pdf\fR\->\fBbleedbox()\fR" 4 .IX Item "($llx,$lly, $urx,$ury) = $pdf->bleedbox()" .PD Sets the global Bleed Box (or page's Bleed Box, if \f(CW\*(C`$page\->\*(C'\fR instead). This is typically used in printing on paper, where you want ink or color (such as thumb tabs) to be printed a bit beyond the final paper size, to ensure that the cut paper \fIbleeds\fR (the cut goes \fIthrough\fR the ink), rather than accidentally leaving some white paper visible outside. Allow enough \*(L"bleed\*(R" over the expected trim line to account for minor variations in paper handling, folding, and cutting; to avoid showing white paper at the edge. The Bleed Box is where \fIprinting\fR could actually extend to; the Trim Box is normally within it, where the paper would actually be \fIcut\fR. The default value is equal to the Crop Box, but is often a bit smaller. The space between the Bleed Box and the Crop Box is available for printer instructions, color alignment dots, etc., while crop marks (trim guides) are at least partly within the bleed area (and should be printed after content is printed). .Sp If no arguments are given, the current Bleed Box (global or page) coordinates are returned instead. The former \f(CW\*(C`get_bleedbox\*(C'\fR (page only) function is \&\fBdeprecated\fR and will likely be removed some time in the future. If a Bleed Box has not been defined, the Crop Box coordinates (if defined) will be returned, otherwise the Media Box coordinates (which always exist) will be returned. In addition, when \fIsetting\fR the Bleed Box, the resulting coordinates are returned. This permits you to specify the bleed box by a name (alias) and get the dimensions back, all in one call. .Sp A global (\s-1PDF\s0 level) bleedbox setting is inherited by each page, or can be overridden by setting bleedbox in the page. As with \f(CW\*(C`mediabox\*(C'\fR, only one bleed box may be set at this (\s-1PDF\s0) level. As with \f(CW\*(C`mediabox\*(C'\fR, a named media size may have an orientation (l or L) for Landscape mode. Note that the \s-1PDF\s0 level global Bleed Box will be used \fIeven if\fR the page gets its own Crop Box. That is, the page's Bleed Box inherits the global Bleed Box, not the page Crop Box, even if the page has its own media size! If you set the page's own Media Box or Crop Box, you should consider also explicitly setting the page Bleed Box (and other boxes). .PP \fITrim Box\fR .IX Subsection "Trim Box" .ie n .IP "$pdf\->trimbox($name)" 4 .el .IP "\f(CW$pdf\fR\->trimbox($name)" 4 .IX Item "$pdf->trimbox($name)" .PD 0 .ie n .IP "$pdf\->trimbox($name, \-orient => 'orientation')" 4 .el .IP "\f(CW$pdf\fR\->trimbox($name, \-orient => 'orientation')" 4 .IX Item "$pdf->trimbox($name, -orient => 'orientation')" .ie n .IP "$pdf\->trimbox($w,$h)" 4 .el .IP "\f(CW$pdf\fR\->trimbox($w,$h)" 4 .IX Item "$pdf->trimbox($w,$h)" .ie n .IP "$pdf\->trimbox($llx,$lly, $urx,$ury)" 4 .el .IP "\f(CW$pdf\fR\->trimbox($llx,$lly, \f(CW$urx\fR,$ury)" 4 .IX Item "$pdf->trimbox($llx,$lly, $urx,$ury)" .ie n .IP "($llx,$lly, $urx,$ury) = $pdf\->\fBtrimbox()\fR" 4 .el .IP "($llx,$lly, \f(CW$urx\fR,$ury) = \f(CW$pdf\fR\->\fBtrimbox()\fR" 4 .IX Item "($llx,$lly, $urx,$ury) = $pdf->trimbox()" .PD Sets the global Trim Box (or page's Trim Box, if \f(CW\*(C`$page\->\*(C'\fR instead). This is supposed to be the actual dimensions of the finished page (after trimming of the paper). In some production environments, it is useful to have printer's instructions, cut marks, and so on outside of the trim box. The default value is equal to Crop Box, but is often a bit smaller than any Bleed Box, to allow the desired \*(L"bleed\*(R" effect. .Sp If no arguments are given, the current Trim Box (global or page) coordinates are returned instead. The former \f(CW\*(C`get_trimbox\*(C'\fR (page only) function is \&\fBdeprecated\fR and will likely be removed some time in the future. If a Trim Box has not been defined, the Crop Box coordinates (if defined) will be returned, otherwise the Media Box coordinates (which always exist) will be returned. In addition, when \fIsetting\fR the Trim Box, the resulting coordinates are returned. This permits you to specify the trim box by a name (alias) and get the dimensions back, all in one call. .Sp A global (\s-1PDF\s0 level) trimbox setting is inherited by each page, or can be overridden by setting trimbox in the page. As with \f(CW\*(C`mediabox\*(C'\fR, only one trim box may be set at this (\s-1PDF\s0) level. As with \f(CW\*(C`mediabox\*(C'\fR, a named media size may have an orientation (l or L) for Landscape mode. Note that the \s-1PDF\s0 level global Trim Box will be used \fIeven if\fR the page gets its own Crop Box. That is, the page's Trim Box inherits the global Trim Box, not the page Crop Box, even if the page has its own media size! If you set the page's own Media Box or Crop Box, you should consider also explicitly setting the page Trim Box (and other boxes). .PP \fIArt Box\fR .IX Subsection "Art Box" .ie n .IP "$pdf\->artbox($name)" 4 .el .IP "\f(CW$pdf\fR\->artbox($name)" 4 .IX Item "$pdf->artbox($name)" .PD 0 .ie n .IP "$pdf\->artbox($name, \-orient => 'orientation')" 4 .el .IP "\f(CW$pdf\fR\->artbox($name, \-orient => 'orientation')" 4 .IX Item "$pdf->artbox($name, -orient => 'orientation')" .ie n .IP "$pdf\->artbox($w,$h)" 4 .el .IP "\f(CW$pdf\fR\->artbox($w,$h)" 4 .IX Item "$pdf->artbox($w,$h)" .ie n .IP "$pdf\->artbox($llx,$lly, $urx,$ury)" 4 .el .IP "\f(CW$pdf\fR\->artbox($llx,$lly, \f(CW$urx\fR,$ury)" 4 .IX Item "$pdf->artbox($llx,$lly, $urx,$ury)" .ie n .IP "($llx,$lly, $urx,$ury) = $pdf\->\fBartbox()\fR" 4 .el .IP "($llx,$lly, \f(CW$urx\fR,$ury) = \f(CW$pdf\fR\->\fBartbox()\fR" 4 .IX Item "($llx,$lly, $urx,$ury) = $pdf->artbox()" .PD Sets the global Art Box (or page's Art Box, if \f(CW\*(C`$page\->\*(C'\fR instead). This is supposed to define "the extent of the page's \&\fImeaningful\fR content (including [margins])\*(L". It might exclude some content, such as Headlines or headings. Any binding or punched-holes margin would typically be outside of the Art Box, as would be page numbers and running headers and footers. The default value is equal to the Crop Box, although normally it would be no larger than any Trim Box. The Art Box may often be used for defining \*(R"important" content (e.g., \fIexcluding\fR advertisements) that may or may not be brought over to another page (e.g., N\-up printing). .Sp If no arguments are given, the current Art Box (global or page) coordinates are returned instead. The former \f(CW\*(C`get_artbox\*(C'\fR (page only) function is \&\fBdeprecated\fR and will likely be removed some time in the future. If an Art Box has not been defined, the Crop Box coordinates (if defined) will be returned, otherwise the Media Box coordinates (which always exist) will be returned. In addition, when \fIsetting\fR the Art Box, the resulting coordinates are returned. This permits you to specify the art box by a name (alias) and get the dimensions back, all in one call. .Sp A global (\s-1PDF\s0 level) artbox setting is inherited by each page, or can be overridden by setting artbox in the page. As with \f(CW\*(C`mediabox\*(C'\fR, only one art box may be set at this (\s-1PDF\s0) level. As with \f(CW\*(C`mediabox\*(C'\fR, a named media size may have an orientation (l or L) for Landscape mode. Note that the \s-1PDF\s0 level global Art Box will be used \fIeven if\fR the page gets its own Crop Box. That is, the page's Art Box inherits the global Art Box, not the page Crop Box, even if the page has its own media size! If you set the page's own Media Box or Crop Box, you should consider also explicitly setting the page Art Box (and other boxes). .PP \fISuggested Box Usage\fR .IX Subsection "Suggested Box Usage" .PP See \f(CW\*(C`examples/Boxes.pl\*(C'\fR for an example of using boxes. .PP How you define your boxes (or let them default) is up to you, depending on whether you're duplex printing \s-1US\s0 Letter or A4 on your laser printer, to be spiral bound on the bind margin, or engaging a professional printer. In the latter case, discuss in advance with the print firm what capabilities (and limitations) they have and what information they need from a \s-1PDF\s0 file. For instance, they may not want a Crop Box defined, and may call for very specific box sizes. For large press runs, they may print multiple pages (N\-up) duplexed on large web roll \&\*(L"signatures\*(R", which are then intricately folded and guillotined (trimmed) and bound together into books or magazines. You would usually just supply a \s-1PDF\s0 with all the pages; they would take care of the signature layout (which includes offsets and 180 degree rotations). .PP (As an aside, don't count on a printer having any particular font available, so be sure to ask. Usually they will want you to embed all fonts used, but ask first, and double-check before handing over the print job! \s-1TTF/OTF\s0 fonts (\f(CW\*(C`ttfont()\*(C'\fR) are embedded by default, but other fonts (core, ps, bdf, cjk) are not! A printer \fImay\fR have a core font collection, but they are free to substitute a \*(L"workalike\*(R" font for any given core font, and the results may not match what you saw on your \s-1PC\s0!) .PP On the assumption that you're using a single sheet (\s-1US\s0 Letter or A4) laser or inkjet printer, are you planning to trim each sheet down to a smaller final size? If so, you can do true bleeds by defining a Trim Box and a slightly larger Bleed Box. You would print bleeds (all the way to the finished edge) out to the Bleed Box, but nothing is enforced about the Bleed Box. At the other end of the spectrum, you would define the Media Box to be the physical paper size being printed on. Most printers reserve a little space on the sides (and possibly top and bottom) for paper handling, so it is often good to define your Crop Box as the printable area. Remember that the Media Box sets the coordinate system used, so you still need to avoid going outside the Crop Box with content (most readers and printers will not show any ink outside of the Crop Box). Whether or not you define a Crop Box, you're going to almost always end up with white paper on at least the sides. .PP For small in-house jobs, you probably won't need color alignment dots and other such professional instructions and information between the Bleed Box and the Crop Box, but crop marks for trimming (if used) should go just outside the Trim Box (partly or wholly within the Bleed Box), and be drawn \fIafter\fR all content. If you're \fInot\fR trimming the paper, don't try to do any bleed effects (including solid background color pages/covers), as you will usually have a white edge around the sheet anyway. Don't count on a \s-1PDF\s0 document \fInever\fR being physically printed, and not just displayed (where you can do things like bleed all the way to the media edge). Finally, for single sheet printing, an Art Box is probably unnecessary, but if you're combining pages into N\-up prints, or doing other manipulations, it may be useful. .PP \fIBox Inheritance\fR .IX Subsection "Box Inheritance" .PP What Media, Crop, Bleed, Trim, and Art Boxes a page gets can be a little complicated. Note that usually, only the Media and Crop Boxes will have a clear visual effect. The visual effect of the other boxes (if any) may be very subtle. .PP First, everything is set at the global (\s-1PDF\s0) level. The Media Box is always defined, and defaults to \s-1US\s0 Letter (8.5 inches wide by 11 inches high). The global Crop Box inherits the Media Box, unless explicitly defined. The Bleed, Trim, and Art Boxes inherit the Crop Box, unless explicitly defined. A global box should only be defined once, as the last one defined is the one that will be written to the \s-1PDF\s0! .PP Second, a page inherits the global boxes, for its initial settings. You may call any of the box set methods (\f(CW\*(C`cropbox\*(C'\fR, \f(CW\*(C`trimbox\*(C'\fR, etc.) to explicitly set (override) any box for \fIthis\fR page. Note that setting a new Media Box for the page does \fBnot\fR reset the page's Crop Box \*(-- it still uses whatever it inherited from the global Crop Box. You would need to explicitly set the page's Crop Box if you want a different setting. Likewise, the page's Bleed, Trim, and Art Boxes will not be reset by a new page Crop Box \*(-- they will still inherit from the global (\s-1PDF\s0) settings. .PP Third, the page Media Box (the one actually used for output pages), clips or limits all the other boxes to extend no larger than its size. For example, if the Media Box is \s-1US\s0 Letter, and you set a Crop Box of A4 size, the smaller of the two heights (11 inches) would be effective, and the smaller of the two widths (8.26 inches, 595 Points) would be effective. The \fIgiven\fR dimensions of a box are returned on query (get), not the \&\fIeffective\fR dimensions clipped by the Media Box. .SS "\s-1FONT METHODS\s0" .IX Subsection "FONT METHODS" \fICore Fonts\fR .IX Subsection "Core Fonts" .PP Core fonts are limited to single byte encodings. You cannot use \s-1UTF\-8\s0 or other multibyte encodings with core fonts. The default encoding for the core fonts is WinAnsiEncoding (roughly the \s-1CP\-1252\s0 superset of \s-1ISO\-8859\-1\s0). See the \&\f(CW\*(C`\-encode\*(C'\fR option below to change this encoding. See \*(L"font automap\*(R" in PDF::Builder::Resource::Font method for information on accessing more than 256 glyphs in a font, using planes, \fIalthough there is no guarantee that future changes to font files will permit consistent results\fR. .PP Note that core fonts use fixed lists of expected glyphs, along with metrics such as their widths. This may not exactly match up with whatever local font file is used by the \s-1PDF\s0 reader. It's usually pretty close, but many cases have been found where the list of glyphs is different between the core fonts and various local font files, so be aware of this. .PP To allow \s-1UTF\-8\s0 text and extended glyph counts, you should consider replacing your use of core fonts with TrueType (.ttf) and OpenType (.otf) fonts. There are tools, such as \fIFontForge\fR, which can do a fairly good (though, not perfect) job of converting a Type1 font library to \s-1OTF.\s0 .PP \&\fBExamples:\fR .PP .Vb 4 \& $font1 = $pdf\->corefont(\*(AqTimes\-Roman\*(Aq, \-encode => \*(Aqlatin2\*(Aq); \& $font2 = $pdf\->corefont(\*(AqTimes\-Bold\*(Aq); \& $font3 = $pdf\->corefont(\*(AqHelvetica\*(Aq); \& $font4 = $pdf\->corefont(\*(AqZapfDingbats\*(Aq); .Ve .PP Valid \f(CW%options\fR are: .IP "\-encode" 4 .IX Item "-encode" Changes the encoding of the font from its default. Notice that the encoding (\fInot\fR the entire font's glyph list) is shown in a \s-1PDF\s0 object (record), listing 256 glyphs associated with this encoding (\fIand\fR that are available in this font). .IP "\-dokern" 4 .IX Item "-dokern" Enables kerning if data is available. .PP \&\fBNotes:\fR .PP Even though these are called \*(L"core\*(R" fonts, they are \fInot\fR shipped with PDF::Builder, but are expected to be found on the machine with the \s-1PDF\s0 reader. Most core fonts are installed with a \s-1PDF\s0 reader, and thus are not coordinated with PDF::Builder. PDF::Builder \fIdoes\fR ship with core font \&\fImetrics\fR files (width, glyph names, etc.), but these cannot be guaranteed to be in sync with what the \s-1PDF\s0 reader has installed! .PP There are some 14 core fonts (regular, italic, bold, and bold-italic for Times [serif], Helvetica [sans serif], Courier [fixed pitch]; plus two symbol fonts) that are supposed to be available on any \s-1PDF\s0 reader, \fBalthough other fonts with very similar metrics are often substituted.\fR You should \fInot\fR count on any of the 15 Windows core fonts (Bank Gothic, Georgia, Trebuchet, Verdana, and two more symbol fonts) being present, especially on Linux, Mac, or other non-Windows platforms. Be aware if you are producing PDFs to be read on a variety of different systems! .PP If you want to ensure the widest portability for a \s-1PDF\s0 document you produce, you should consider using \s-1TTF\s0 fonts (instead of core fonts) and embedding them in the document. This ensures that there will be no substitutions, that all metrics are known and match the glyphs, \s-1UTF\-8\s0 encoding can be used, and that the glyphs \fIwill\fR be available on the reader's machine. At least on Windows platforms, most of the fonts are \s-1TTF\s0 anyway, which are used behind the scenes for \*(L"core\*(R" fonts, while missing most of the capabilities of \s-1TTF\s0 (now or possibly later in PDF::Builder) such as embedding, ligatures, \s-1UTF\-8,\s0 etc. The downside is, obviously, that the resulting \s-1PDF\s0 file will be larger because it includes the font(s). There \fImight\fR also be copyright or licensing issues with the redistribution of font files in this manner (you might want to check, before widely distributing a \s-1PDF\s0 document with embedded fonts, although many \&\fIdo\fR permit the part of the font used, to be embedded.). .PP See also PDF::Builder::Resource::Font::CoreFont. .PP \fI\s-1PS\s0 Fonts\fR .IX Subsection "PS Fonts" .PP \&\s-1PS\s0 (T1) fonts are limited to single byte encodings. You cannot use \s-1UTF\-8\s0 or other multibyte encodings with T1 fonts. The default encoding for the T1 fonts is WinAnsiEncoding (roughly the \s-1CP\-1252\s0 superset of \s-1ISO\-8859\-1\s0). See the \&\f(CW\*(C`\-encode\*(C'\fR option below to change this encoding. See \*(L"font automap\*(R" in PDF::Builder::Resource::Font method for information on accessing more than 256 glyphs in a font, using planes, \fIalthough there is no guarantee that future changes to font files will permit consistent results\fR. \&\fBNote:\fR many Type1 fonts are limited to 256 glyphs, but some are available with more than 256 glyphs. Still, a maximum of 256 at a time are usable. .PP \&\f(CW\*(C`psfont\*(C'\fR accepts both \s-1ASCII\s0 (.pfa) and binary (.pfb) Type1 glyph files. Font metrics can be supplied in either \s-1ASCII\s0 (.afm) or binary (.pfm) format, as can be seen in the examples given below. It is possible to use .pfa with .pfm and .pfb with .afm if that's what's available. The \s-1ASCII\s0 and binary files have the same content, just in different formats. .PP To allow \s-1UTF\-8\s0 text and extended glyph counts in one font, you should consider replacing your use of Type1 fonts with TrueType (.ttf) and OpenType (.otf) fonts. There are tools, such as \fIFontForge\fR, which can do a fairly good (though, not perfect) job of converting your font library to \s-1OTF.\s0 .PP \&\fBExamples:\fR .PP .Vb 2 \& $font1 = $pdf\->psfont(\*(AqTimes\-Book.pfa\*(Aq, \-afmfile => \*(AqTimes\-Book.afm\*(Aq); \& $font2 = $pdf\->psfont(\*(Aq/fonts/Synest\-FB.pfb\*(Aq, \-pfmfile => \*(Aq/fonts/Synest\-FB.pfm\*(Aq); .Ve .PP Valid \f(CW%options\fR are: .IP "\-encode" 4 .IX Item "-encode" Changes the encoding of the font from its default. Notice that the encoding (\fInot\fR the entire font's glyph list) is shown in a \s-1PDF\s0 object (record), listing 256 glyphs associated with this encoding (\fIand\fR that are available in this font). .IP "\-afmfile" 4 .IX Item "-afmfile" Specifies the location of the \fI\s-1ASCII\s0\fR font metrics file (.afm). It may be used with either an \s-1ASCII\s0 (.pfa) or binary (.pfb) glyph file. .IP "\-pfmfile" 4 .IX Item "-pfmfile" Specifies the location of the \fIbinary\fR font metrics file (.pfm). It may be used with either an \s-1ASCII\s0 (.pfa) or binary (.pfb) glyph file. .IP "\-dokern" 4 .IX Item "-dokern" Enables kerning if data is available. .PP \&\fBNote:\fR these T1 (Type1) fonts are \fInot\fR shipped with PDF::Builder, but are expected to be found on the machine with the \s-1PDF\s0 reader. Most \s-1PDF\s0 readers do not install T1 fonts, and it is up to the user of the \s-1PDF\s0 reader to install the needed fonts. Unlike TrueType fonts, \s-1PS\s0 (T1) fonts are not embedded in the \&\s-1PDF,\s0 and must be supplied on the Reader end. .PP See also PDF::Builder::Resource::Font::Postscript. .PP \fITrueType Fonts\fR .IX Subsection "TrueType Fonts" .PP \&\fBWarning:\fR BaseEncoding is \fInot\fR set by default for TrueType fonts, so \fBtext in the \s-1PDF\s0 isn't searchable\fR (by the \s-1PDF\s0 reader) unless a ToUnicode CMap is included. A ToUnicode CMap \fIis\fR included by default (\-unicodemap set to 1) by PDF::Builder, but allows it to be disabled (for performance and file size reasons) by setting \-unicodemap to 0. This will produce non-searchable text, which, besides being annoying to users, may prevent screen readers and other aids to disabled users from working correctly! .PP \&\fBExamples:\fR .PP .Vb 2 \& $font1 = $pdf\->ttfont(\*(AqTimes.ttf\*(Aq); \& $font2 = $pdf\->ttfont(\*(AqGeorgia.otf\*(Aq); .Ve .PP Valid \f(CW%options\fR are: .IP "\-encode" 4 .IX Item "-encode" Changes the encoding of the font from its default (WinAnsiEncoding). .Sp Note that for a single byte encoding (e.g., 'latin1'), you are limited to 256 characters defined for that encoding. 'automap' does not work with TrueType. If you want more characters than that, use 'utf8' encoding with a \s-1UTF\-8\s0 encoded text string. .IP "\-isocmap" 4 .IX Item "-isocmap" Use the \s-1ISO\s0 Unicode Map instead of the default \s-1MS\s0 Unicode Map. .IP "\-unicodemap" 4 .IX Item "-unicodemap" If 1 (default), output ToUnicode CMap to permit text searches and screen readers. Set to 0 to save space by \fInot\fR including the ToUnicode CMap, but text searching and screen reading will not be possible. .IP "\-dokern" 4 .IX Item "-dokern" Enables kerning if data is available. .IP "\-noembed" 4 .IX Item "-noembed" Disables embedding of the font file. \fBNote that this is potentially hazardous, as the glyphs provided on the \s-1PDF\s0 reader machine may not match what was used on the \s-1PDF\s0 writer machine (the one running PDF::Builder)!\fR If you know \fIfor sure\fR that all \s-1PDF\s0 readers will be using the same \s-1TTF\s0 or \s-1OTF\s0 file you're using with PDF::Builder; not embedding the font may be acceptable, in return for a smaller \&\s-1PDF\s0 file size. Note that the Reader needs to know where to find the font file \&\*(-- it can't be in any random place, but typically needs to be listed in a path that the Reader follows. Otherwise, it will be unable to render the text! .Sp The only value for the \f(CW\*(C`\-noembed\*(C'\fR flag currently checked for is \fB1\fR, which means to \fInot\fR embed the font file in the \s-1PDF.\s0 Any other value currently results in the font file being embedded (by \fBdefault\fR), although in the future, other values might be given significance (such as checking permission bits). .Sp Some additional comments on embedding font file(s) into the \s-1PDF:\s0 besides substantially increasing the size of the \s-1PDF\s0 (even if the font is subsetted, by default), PDF::Builder does not check the font file for any flags indicating font licensing issues and limitations on use. A font foundry may not permit embedding at all, may permit a subset of the font to be embedded, may permit a full font to be embedded, and may specify what can be done with an embedded font (e.g., may or may not be extracted for further use beyond displaying this one \s-1PDF\s0). When you choose to use (and embed) a font, you should be aware of any such licensing issues. .IP "\-nosubset" 4 .IX Item "-nosubset" Disables subsetting of a \s-1TTF/OTF\s0 font, when embedded. By default, only the glyphs used by a document are included in the file, and \fInot\fR the entire font. This can result in a tremendous savings in \s-1PDF\s0 file size. If you intend to allow the \s-1PDF\s0 to be edited by users, not having the entire font glyph set available may cause problems, so be aware of that (and consider using \&\f(CW\*(C`\-nosubset => 1\*(C'\fR. Setting this flag to any value results in the entire font glyph set being embedded in the file. It might be a good idea to use only the value \fB1\fR, in case other values are assigned roles in the future. .IP "\-debug" 4 .IX Item "-debug" If set to 1 (default is 0), diagnostic information is output about the CMap processing. .IP "\-usecmf" 4 .IX Item "-usecmf" If set to 1 (default is 0), the first priority is to make use of one of the four \f(CW\*(C`.cmap\*(C'\fR files for \s-1CJK\s0 fonts. This is the \fIold\fR way of processing \s-1TTF\s0 files. If, after all is said and done, a working \fIinternal\fR CMap hasn't been found (for \-usecmf=>0), \f(CW\*(C`ttfont()\*(C'\fR will fall back to using a \f(CW\*(C`.cmap\*(C'\fR file if possible. .IP "\-cmaps" 4 .IX Item "-cmaps" This flag may be set to a string listing the Platform/Encoding pairs to look for of any internal CMaps in the font file, in the desired order (highest priority first). If one list (comma and/or space-separated pairs) is given, it is used for both Windows and non-Windows platforms (on which PDF::Builder is running, \fInot\fR the \s-1PDF\s0 reader's). Two lists, separated by a semicolon ; may be given, with the first being used for a Windows platform and the second for non-Windows. The default list is \f(CW\*(C`0/6 3/10 0/4 3/1 0/3; 0/6 0/4 3/10 0/3 3/1\*(C'\fR. Finally, instead of a P/E list, a string \f(CW\*(C`find_ms\*(C'\fR may be given to tell it to simply call the Font::TTF \f(CW\*(C`find_ms()\*(C'\fR method to find a (preferably Windows) internal CMap. \f(CW\*(C`\-cmaps\*(C'\fR set to 'find_ms' would emulate the \fIold\fR way of looking for CMaps. Symbol fonts (3/0) always use \fBfind_ms()\fR, and the new default lookup is (if \f(CW\*(C`.cmap\*(C'\fR isn't used, see \f(CW\*(C`\-usecmf\*(C'\fR) to try to get a match with the default list for the appropriate \s-1OS.\s0 If none can be found, \fBfind_ms()\fR is tried, and as last resort use the \f(CW\*(C`.cmap\*(C'\fR (if available), even if \f(CW\*(C`\-usecmf\*(C'\fR is not 1. .PP \fI\s-1CJK\s0 Fonts\fR .IX Subsection "CJK Fonts" .PP \&\fBExamples:\fR .PP .Vb 2 \& $font = $pdf\->cjkfont(\*(Aqkorean\*(Aq); \& $font = $pdf\->cjkfont(\*(Aqtraditional\*(Aq); .Ve .PP Valid \f(CW%options\fR are: .IP "\-encode" 4 .IX Item "-encode" Changes the encoding of the font from its default. .PP \&\fBWarning:\fR Unlike \f(CW\*(C`ttfont\*(C'\fR, the font file is \fInot\fR embedded in the output \&\s-1PDF\s0 file. This is evidently behavior left over from the early days of \s-1CJK\s0 fonts, where the \&\f(CW\*(C`Cmap\*(C'\fR and \f(CW\*(C`Data\*(C'\fR were always external files, rather than internal tables. If you need a CJK-using \s-1PDF\s0 file to embed the font, for portability, you can create a \s-1PDF\s0 using \f(CW\*(C`cjkfont\*(C'\fR, and then use an external utility (e.g., \&\f(CW\*(C`pdfcairo\*(C'\fR) to embed the font in the \s-1PDF.\s0 It may also be possible to use \&\f(CW\*(C`ttfont\*(C'\fR instead, to produce the \s-1PDF,\s0 provided you can deduce the correct font file name from examining the \s-1PDF\s0 file (e.g., on my Windows system, the \&\*(L"Ming\*(R" font would be \f(CW\*(C`$font = $pdf\->ttfont("C:/Program Files (x86)/Adobe/Acrobat Reader DC/Resource/CIDFont/AdobeMingStd\-Light.otf")\*(C'\fR. Of course, the font file used would have to be \f(CW\*(C`.ttf\*(C'\fR or \f(CW\*(C`.otf\*(C'\fR. It may act a little differently than \f(CW\*(C`cjkfont\*(C'\fR (due a a different Cmap), but you \fIshould\fR be able to embed the font file into the \s-1PDF.\s0 .PP See also PDF::Builder::Resource::CIDFont::CJKFont .PP \fISynthetic Fonts\fR .IX Subsection "Synthetic Fonts" .PP \&\fBWarning:\fR BaseEncoding is \fInot\fR set by default for these fonts, so text in the \s-1PDF\s0 isn't searchable (by the \s-1PDF\s0 reader) unless a ToUnicode CMap is included. A ToUnicode CMap \fIis\fR included by default (\-unicodemap set to 1) by PDF::Builder, but allows it to be disabled (for performance and file size reasons) by setting \-unicodemap to 0. This will produce non-searchable text, which, besides being annoying to users, may prevent screen readers and other aids to disabled users from working correctly! .PP \&\fBExamples:\fR .PP .Vb 4 \& $cf = $pdf\->corefont(\*(AqTimes\-Roman\*(Aq, \-encode => \*(Aqlatin1\*(Aq); \& $sf = $pdf\->synfont($cf, \-condense => 0.85); # compressed 85% \& $sfb = $pdf\->synfont($cf, \-bold => 1); # embolden by 10em \& $sfi = $pdf\->synfont($cf, \-oblique => \-12); # italic at \-12 degrees .Ve .PP Valid \f(CW%options\fR are: .IP "\-condense" 4 .IX Item "-condense" Character width condense/expand factor (0.1\-0.9 = condense, 1 = normal/default, 1.1+ = expand). It is the multiplier to apply to the width of each character. .IP "\-slant" 4 .IX Item "-slant" \&\fB\s-1DEPRECATED\s0\fR. It is the old name for \f(CW\*(C`\-condense\*(C'\fR, and will eventually be removed. Use \f(CW\*(C`\-condense\*(C'\fR instead. .IP "\-oblique" 4 .IX Item "-oblique" Italic angle (+/\- degrees, default 0), sets \fBskew\fR of character box. .IP "\-bold" 4 .IX Item "-bold" Emboldening factor (0.1+, bold = 1, heavy = 2, ...), additional thickness to draw outline of character (with a heavier \fBline width\fR) before filling. .IP "\-space" 4 .IX Item "-space" Additional character spacing in milliems (0\-1000) .IP "\-caps" 4 .IX Item "-caps" 0 for normal text, 1 for small caps. Implemented by asking the font what the uppercased translation (single character) is for a given character, and outputting it at 80% height and 88% width (heavier vertical stems are better looking than a straight 80% scale). .Sp Note that only lower case letters which appear in the \*(L"standard\*(R" font (plane 0 for core fonts and \s-1PS\s0 fonts) will be small-capped. This may include eszett (German sharp s), which becomes \s-1SS,\s0 and dotless i and j which become I and J respectively. There are many other accented Latin alphabet letters which \fImay\fR show up in planes 1 and higher. Ligatures (e.g., ij and ffl) do not have uppercase equivalents, nor does a long s. If you have text which includes such characters, you may want to consider preprocessing it to replace them with Latin character expansions (e.g., i+j and f+f+l) before small-capping. .PP Note that \fI\s-1CJK\s0\fR fonts (created with the \f(CW\*(C`cjkfont\*(C'\fR method) do \fBnot\fR work properly with \f(CW\*(C`synfont\*(C'\fR. This is due to a different internal structure of the \&\fI\s-1CJK\s0\fR fonts, as compared to \fIcorefont\fR, \fIttfont\fR, and \fIpsfont\fR base fonts. If you require a synthesized (modified) \s-1CJK\s0 font, you might try finding the \&\s-1TTF\s0 or \s-1OTF\s0 original, use \f(CW\*(C`ttfont\*(C'\fR to create the base font, and running \&\f(CW\*(C`synfont\*(C'\fR against that, in the manner described for embedding \*(L"\s-1CJK\s0 Fonts\*(R". .PP See also PDF::Builder::Resource::Font::SynFont .SS "\s-1IMAGE METHODS\s0" .IX Subsection "IMAGE METHODS" This is additional information on enhanced libraries available for \s-1TIFF\s0 and \&\s-1PNG\s0 images. See specific information listings for \s-1GD, GIF, JPEG,\s0 and \s-1PNM\s0 image formats. In addition, see \f(CW\*(C`examples/Content.pl\*(C'\fR for an example of placing an image on a page, as well as using in a \*(L"Form\*(R". .PP \fIWhy is my image flipped or rotated?\fR .IX Subsection "Why is my image flipped or rotated?" .PP Something not uncommonly seen when using \s-1JPEG\s0 photos in a \s-1PDF\s0 is that the images will be rotated and/or mirrored (flipped). This may happen when using \&\s-1TIFF\s0 images too. What happens is that the camera stores an image just as it comes off the \s-1CCD\s0 sensor, regardless of the camera orientation, and does not rotate it to the correct orientation! It \fIdoes\fR store a separate \&\*(L"orientation\*(R" flag to suggest how the image might be corrected, but not all image processing obeys this flag (PDF::Builder does \fBnot\fR.). For example, if you take a \*(L"portrait\*(R" (tall) photo of a tree (with the phone held vertically), and then use it in a \s-1PDF,\s0 the tree may appear to have been cut down! (appears in landscape mode) .PP I have found some code that should allow the \f(CW\*(C`image_jpeg\*(C'\fR or \f(CW\*(C`image\*(C'\fR routine to auto-rotate to (supposedly) the correct orientation, by looking for the Exif metadata \*(L"Orientation\*(R" tag in the file. However, three problems arise: \&\fB1)\fR if a photo has been edited, and rotated or flipped in the process, there is no guarantee that the Orientation tag has been corrected. \&\fB2)\fR more than one Orientation tag may exist (e.g., in the binary APP1/Exif header, \fIand\fR in \s-1XML\s0 data), and they may not agree with each other \*(-- which should be used? \&\fB3)\fR 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 \s-1PDF.\s0 This is costly and error-prone. In any case, the user would need to be able to override any auto-rotate function. .PP For the time being, PDF::Builder will simply leave it up to the user of the library to take care of rotating and/or flipping an image which displays incorrectly. It is possible that we will consider adding some sort of query or warning that the image appears to \fInot\fR be \*(L"normally\*(R" oriented (Orientation value 1 or \*(L"Top-left\*(R"), according to the Orientation flag. You can consider either (re\-)saving the photo in an editor such as PhotoShop or \s-1GIMP,\s0 or using PDF::Builder code similar to the following (for images rotated 180 degrees): .PP .Vb 7 \& $pW = 612; $pH = 792; # page dimensions (US Letter) \& my $img = $pdf\->image_jpeg("AliceLake.jpeg"); \& # raw size WxH 4032x3024, scaled down to 504x378 \& $sW = 4032/8; $sH = 3024/8; \& # intent is to center on US Letter sized page (LL at 54,207) \& # Orientation flag on this image is 3 (rotated 180 degrees). \& # if naively displayed (just $gfx\->image call), it will be upside down \& \& $gfx\->save(); \& \& ## method 0: simple display, is rotated 180 degrees! \& #$gfx\->image($img, ($pW\-$sW)/2,($pH\-$sH)/2, $sW,$sH); \& \& ## method 1: translate, then rotate \& #$gfx\->translate($pW,$pH); # to new origin (media UR corner) \& #$gfx\->rotate(180); # rotate around new origin \& #$gfx\->image($img, ($pW\-$sW)/2,($pH\-$sH)/2, $sW,$sH); \& # image\*(Aqs UR corner, not LL \& \& # method 2: rotate, then translate \& $gfx\->rotate(180); # rotate around current origin \& $gfx\->translate(\-$sW,\-$sH); # translate in rotated coordinates \& $gfx\->image($img, \-($pW\-$sW)/2,\-($pH\-$sH)/2, $sW,$sH); \& # image\*(Aqs UR corner, not LL \& \& ## method 3: flip (mirror) twice \& #$scale = 1; # not rescaling here \& #$size_page = $pH/$scale; \& #$invScale = 1.0/$scale; \& #$gfx\->add("\-$invScale 0 0 \-$invScale 0 $size_page cm"); \& #$gfx\->image($img, \-($pW\-$sW)/2\-$sW,($pH\-$sH)/2, $sW,$sH); \& \& $gfx\->restore(); .Ve .PP If your image is also mirrored (flipped about an axis), simple rotation will not suffice. You could do something with a reversal of the coordinate system, as in \*(L"method 3\*(R" above (see \*(L"Advanced Methods\*(R" in PDF::Builder::Content). To mirror only left/right, the second \f(CW$invScale\fR 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. 90 or 270 degree rotations will require a \f(CW\*(C`rotate\*(C'\fR call, possibly with \*(L"cm\*(R" usage to reverse mirroring. Incidentally, do not confuse this issue with the coordinate flipping performed by some Chrome browsers when printing a page to \s-1PDF.\s0 .PP Note that \s-1TIFF\s0 images may have the same rotation/mirroring problems as \s-1JPEG,\s0 which is not surprising, as the Exif format was lifted from \s-1TIFF\s0 for use in \&\s-1JPEG.\s0 The cure will be similar to \s-1JPEG\s0's. .PP \fI\s-1TIFF\s0 Images\fR .IX Subsection "TIFF Images" .PP Note that the Graphics::TIFF support library does \fBnot\fR currently permit a filehandle for \f(CW$file\fR. .PP PDF::Builder will use the Graphics::TIFF support library for \s-1TIFF\s0 functions, if it is available, unless explicitly told not to. Your code can test whether Graphics::TIFF is available by examining \f(CW\*(C`$tiff\->usesLib()\*(C'\fR or \&\f(CW\*(C`$pdf\->LA_GT()\*(C'\fR. .IP "= \-1" 4 .IX Item "= -1" Graphics::TIFF \fIis\fR installed, but your code has specified \f(CW\*(C`\-nouseGT\*(C'\fR, to \&\fInot\fR use it. The old, pure Perl, code (buggy!) will be used instead, as if Graphics::TIFF was not installed. .IP "= 0" 4 .IX Item "= 0" Graphics::TIFF is \fInot\fR installed. Not all systems are able to successfully install this package, as it requires libtiff.a. .IP "= 1" 4 .IX Item "= 1" Graphics::TIFF is installed and is being used. .PP Options: .IP "\-nouseGT => 1" 4 .IX Item "-nouseGT => 1" Do \fBnot\fR use the Graphics::TIFF library, even if it's available. Normally you \fIwould\fR want to use this library, but there may be cases where you don't, such as when you want to use a file \fIhandle\fR instead of a \fIname\fR. .IP "\-silent => 1" 4 .IX Item "-silent => 1" Do not give the message that Graphics::TIFF is not \fBinstalled\fR. This message will be given only once, but you may want to suppress it, such as during t\-tests. .PP \fI\s-1PNG\s0 Images\fR .IX Subsection "PNG Images" .PP PDF::Builder will use the Image::PNG::Libpng support library for \s-1PNG\s0 functions, if it is available, unless explicitly told not to. Your code can test whether Image::PNG::Libpng is available by examining \f(CW\*(C`$png\->usesLib()\*(C'\fR or \&\f(CW\*(C`$pdf\->LA_IPL()\*(C'\fR. .IP "= \-1" 4 .IX Item "= -1" Image::PNG::Libpng \fIis\fR installed, but your code has specified \f(CW\*(C`\-nouseIPL\*(C'\fR, to \fInot\fR use it. The old, pure Perl, code (slower and less capable) will be used instead, as if Image::PNG::Libpng was not installed. .IP "= 0" 4 .IX Item "= 0" Image::PNG::Libpng is \fInot\fR installed. Not all systems are able to successfully install this package, as it requires libpng.a. .IP "= 1" 4 .IX Item "= 1" Image::PNG::Libpng is installed and is being used. .PP Options: .IP "\-nouseIPL => 1" 4 .IX Item "-nouseIPL => 1" Do \fBnot\fR use the Image::PNG::Libpng library, even if it's available. Normally you \fIwould\fR want to use this library, when available, but there may be cases where you don't. .IP "\-silent => 1" 4 .IX Item "-silent => 1" Do not give the message that Image::PNG::Libpng is not \fBinstalled\fR. This message will be given only once, but you may want to suppress it, such as during t\-tests. .IP "\-notrans => 1" 4 .IX Item "-notrans => 1" No transparency \*(-- ignore tRNS chunk if provided, ignore Alpha channel if provided. .SS "\s-1USING SHAPER\s0 (HarfBuzz::Shaper library)" .IX Subsection "USING SHAPER (HarfBuzz::Shaper library)" .Vb 10 \& # if HarfBuzz::Shaper is not installed, either bail out, or try to \& # use regular TTF calls instead \& my $rc; \& $rc = eval { \& require HarfBuzz::Shaper; \& 1; \& }; \& if (!defined $rc) { $rc = 0; } \& if ($rc == 0) { \& # bail out in some manner \& } else { \& # can use Shaper \& } \& \& my $fontfile = \*(Aq/WINDOWS/Fonts/times.ttf\*(Aq; # used by both Shaper and textHS \& my $fontsize = 15; # used by both Shaper and textHS \& my $font = $pdf\->ttfont($fontfile); \& $text\->font($font, $fontsize); \& \& my $hb = HarfBuzz::Shaper\->new(); # only need to set up once \& my %settings; # for textHS(), not Shaper \& $settings{\*(Aqdump\*(Aq} = 1; # see the diagnostics \& $settings{\*(Aqscript\*(Aq} = \*(AqLatn\*(Aq; \& $settings(\*(Aqdir\*(Aq} = \*(AqL\*(Aq; # LTR \& $settings{\*(Aqfeatures\*(Aq} = (); # required \& \& # \-\- set language (override automatic setting) \& #$settings{\*(Aqlanguage\*(Aq} = \*(Aqen\*(Aq; \& #$hb\->set_language( \*(Aqen_US\*(Aq ); \& # \-\- turn OFF ligatures \& #push @{ $settings{\*(Aqfeatures\*(Aq} }, \*(Aq\-liga\*(Aq; \& #$hb\->add_features( \*(Aq\-liga\*(Aq ); \& # \-\- turn OFF kerning \& #push @{ $settings{\*(Aqfeatures\*(Aq} }, \*(Aq\-kern\*(Aq; \& #$hb\->add_features( \*(Aq\-kern\*(Aq ); \& $hb\->set_font($fontfile); \& $hb\->set_size($fontsize); \& $hb\->set_text("Let\*(Aqs eat waffles in the field for brunch."); \& # expect ffl and fi ligatures, and perhaps some kerning \& \& my $info = $hb\->shaper(); \& $text\->textHS($info, \e%settings); # \-strikethru, \-underline allowed .Ve .PP The package HarfBuzz::Shaper may be optionally installed in order to use the text-shaping capabilities of the HarfBuzz library. These include kerning and ligatures in Western scripts (such as the Latin alphabet). More complex scripts can be handled, such as Arabic family and Indic scripts, where multiple forms of a character may be automatically selected, characters may be reordered, and other modifications made. The examples/HarfBuzz.pl script gives some examples of what may be done. .PP Keep in mind that HarfBuzz works only with TrueType (.ttf) and OpenType (.otf) font files. It will not work with PostScript (Type1), core, bitmapped, or \s-1CJK\s0 fonts. Not all .ttf fonts have the instructions necessary to guide HarfBuzz, but most proper .otf fonts do. In other words, there are no guarantees that a particular font file will work with Shaper! .PP The basic idea is to break up text into \*(L"chunks\*(R" which are of the same script (alphabet), language, direction, font face, font size, and variant (italic, bold, etc.). These could range from a single character to paragraph-length strings of text. These are fed to HarfBuzz::Shaper, along with flags, the font file to be used, and other supporting information, to create an array of output glyphs. Each element is a hash describing the glyph to be output, including its name (if available), its glyph \&\s-1ID\s0 (number) in the selected font, its x and y displacement (usually 0), and its \*(L"advance\*(R" x and y values, all in points. For horizontal languages (\s-1LTR\s0 and \&\s-1RTL\s0), the y advance is normally 0 and the x advance is the font's character width, less any kerning amount. .PP 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 can be overridden, but currently the script and text direction cannot be overridden. .PP \&\fBAn important note:\fR the number of glyphs (array elements) may not be equal to the number of Unicode points (characters) given in the chunk's text string! Sometimes a character will be decomposed into several pieces (multiple glyphs); sometimes multiple characters may be combined into a single ligature glyph; and characters may be reordered (especially in Indic and Southeast Asian languages). As well, for Right-to-Left (bidirectional) scripts such as Hebrew and Arabic families, the text is output in Left-to-Right order (reversed from the input). .PP With due care, a Shaper array can be manipulated in code. The elements are more or less independent of each other, so elements can be modified, rearranged, inserted, or deleted. You might adjust the position of a glyph with 'dx' and \&'dy' hash elements. The 'ax' value should be left alone, so that the wrong kerning isn't calculated, but you might need to adjust the \*(L"advance x\*(R" value by means of one of the following: .IP "\fBaxs\fR is a value to be \fIsubstituted\fR for 'ax' (points)" 4 .IX Item "axs is a value to be substituted for 'ax' (points)" .PD 0 .IP "\fBaxsp\fR is a \fIsubstituted\fR value (\fIpercentage\fR) of the original 'ax'" 4 .IX Item "axsp is a substituted value (percentage) of the original 'ax'" .IP "\fBaxr\fR \fIreduces\fR 'ax' by the value (points). If negative, increase 'ax'" 4 .IX Item "axr reduces 'ax' by the value (points). If negative, increase 'ax'" .IP "\fBaxrp\fR \fIreduces\fR 'ax' by the given \fIpercentage\fR. Again, negative increases 'ax'" 4 .IX Item "axrp reduces 'ax' by the given percentage. Again, negative increases 'ax'" .PD .PP \&\fBCaution:\fR a given character's glyph \s-1ID\s0 is \fInot\fR necessarily going to be the same between any two fonts! For example, an \s-1ASCII\s0 space (U+0020) might be \&\f(CW\*(C`<0001>\*(C'\fR in one font, and \f(CW\*(C`<0003>\*(C'\fR in another font (even one closely related!). A U+00A0 required blank (non-breaking space) may be output as a regular \s-1ASCII\s0 space U+0020. Take care if you need to find a particular glyph in the array, especially if the number of elements don't match. Consider making a text string of \*(L"marker\*(R" characters (space, nbsp, hyphen, soft hyphen, etc.) and processing it through HarfBuzz::Shaper to get the corresponding glyph numbers. You may have to count spaces, say, to see where you could break a glyph array to fit a line. .PP The \f(CW\*(C`advancewidthHS()\*(C'\fR method uses the same inputs as does \f(CW\*(C`textHS()\*(C'\fR. Like \f(CW\*(C`advancewidth()\*(C'\fR, it returns the chunk length in points. Unlike \&\f(CW\*(C`advancewidth()\*(C'\fR, you cannot override the glyph array's font, font size, etc. .PP Once you have your (possibly modified) array of glyphs, you feed it to the \&\f(CW\*(C`textHS()\*(C'\fR method to render it to the page. Remember that this method handles only a single line of text; it does not do line splitting or fitting \*(-- that \&\fIyou\fR currently need to do manually. For Western scripts (e.g., Latin), that might not be too difficult, but for other scripts that involve extensive modification of the raw characters, it may be quite difficult to split \&\fIwords\fR, but you still may be able to split at inter-word spaces. .PP A useful, but not exhaustive, set of functions are allowed by \f(CW\*(C`textHS()\*(C'\fR use. Support includes direction setting (top-to-bottom and bottom-to-top directions, e.g., for Far Eastern languages in traditional orientation), and explicit script names and language (depending on what support HarfBuzz itself gives). \&\fBNot yet\fR supported are features such as discretionary ligatures and manual selection of glyphs (e.g., swashes and alternate forms). .PP Currently, \f(CW\*(C`textHS()\*(C'\fR can only handle a single text string. We are looking at how fitting to a line length (splitting up an array) could be done, as well as how words might be split on hard and soft hyphens. At some point, full paragraph and page shaping could be possible.