.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man v6.0.2 (Pod::Simple 3.45) .\" .\" 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 .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . 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 .\" .\" Required to disable full justification in groff 1.23.0. .if n .ds AD l .\" ======================================================================== .\" .IX Title "PDF::Builder::Page 3" .TH PDF::Builder::Page 3 2026-02-08 "perl v5.42.0" "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::Page \- Methods to interact with individual pages .PP Inherits from PDF::Builder::Basic::PDF::Pages .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& my $pdf = PDF::Builder\->new(); \& \& # Add a page to a new or existing PDF \& my $page = $pdf\->page(); \& \& # Set the physical (media) page size \& # Set prepress page boundaries, a convenience function for those times when \& # it is not necessary to set other prepress (print\-related) page boundaries \& $page\->size(\*(Aqletter\*(Aq); # by common size name \& #$page\->size([0, 0, 612, 792]); # by points LLx,LLy, URx,URy \& \& # alternately, can set (or get) prepress page boundaries \& $page\->boundaries(\*(Aqmedia\*(Aq => \*(Aq12x18\*(Aq, \*(Aqtrim\*(Aq => 0.5 * 72); \& \& # Add an image \& my $image = $pdf\->image(\*(Aq/path/to/file.jpg\*(Aq); \& $page\->object($image, $x,$y, $w,$h); \& \& # Create a content object for text \& my $text = $page\->text(); \& \& # Create a content object for drawing shapes \& my $canvas = $page\->graphics(); # or gfx() \& \& # Now to draw graphics (using $canvas object) and text (using $text object). \& # NOTE that everything in the graphics (canvas) object will be laid down on \& # the page BEFORE anything in the text object is laid down. That is, \& # text will cover graphics, but not vice\-versa. This is simply due to \& # the order in which the objects were defined. .Ve .SH METHODS .IX Header "METHODS" .SS new .IX Subsection "new" .Vb 1 \& $page = PDF::Builder::Page\->new($pdf, $parent, $index) .Ve .Sp .RS 4 Returns a page object (called from \f(CW$pdf\fR\->\fBpage()\fR). .RE .SS "Page Size Methods" .IX Subsection "Page Size Methods" \fIPage Sizes\fR .IX Subsection "Page Sizes" .PP PDF page sizes are stored as rectangular coordinates. For convenience, PDF::Builder also supports a number of aliases and shortcuts that are more human\-friendly. The following formats are available: .IP "a standard paper size" 4 .IX Item "a standard paper size" .Vb 1 \& $page\->boundaries(\*(Aqmedia\*(Aq => \*(AqA4\*(Aq); .Ve .Sp Aliases for the most common paper sizes are built in (case\-insensitive). US: Letter, Legal, Ledger, Tabloid (and others) Metric: 4A0, 2A0, A0 \- A6, 4B0, 2B0, and B0 \- B6 (and others) .Sp See PDF::Builder::Resource::PaperSizes for the full list. .IP "a ""WxH"" string in inches" 4 .IX Item "a ""WxH"" string in inches" .Vb 1 \& $page\->boundaries(\*(Aqmedia\*(Aq => \*(Aq8.5x11\*(Aq); .Ve .Sp Many US paper sizes are commonly identified by their size in inches rather than by a particular name. These can be passed as strings with the width and height separated by an \f(CW\*(C`x\*(C'\fR. Examples: \f(CW\*(C`4x6\*(C'\fR, \f(CW\*(C`12x18\*(C'\fR, \f(CW\*(C`8.5x11\*(C'\fR .IP "a number representing a reduction (in points) from the next\-larger box" 4 .IX Item "a number representing a reduction (in points) from the next-larger box" For example, a 12" x 18" physical sheet to be trimmed down to an 11" x 17" sheet can be specified as follows: .Sp .Vb 2 \& # Note: There are 72 points per inch \& $page\->boundaries(\*(Aqmedia\*(Aq => \*(Aq12x18\*(Aq, \*(Aqtrim\*(Aq => 0.5 * 72); \& \& # Equivalent \& $page\->boundaries(\*(Aqmedia\*(Aq => [0, 0, 12 * 72, 18 * 72], \& \*(Aqtrim\*(Aq => [0.5 * 72, 0.5 * 72, 11.5 * 72, 17.5 * 72]); .Ve .Sp This example shows a 12" x 18" physical sheet that will be reduced to a final size of 11" x 17" by trimming 0.5" from each edge. The smaller page boundary is assumed to be centered within the larger one. .Sp The "next\-larger box" follows this order, stopping at the first defined value: .Sp .Vb 2 \& art \-> trim \-> bleed \-> media \& crop \-> media .Ve .Sp This option isn\*(Aqt available for the media box, since it is by definition, the largest boundary. .ie n .IP "[$width, $height] in points" 4 .el .IP "[$width, \f(CW$height\fR] in points" 4 .IX Item "[$width, $height] in points" .Vb 1 \& $page\->boundaries(\*(Aqmedia\*(Aq => [8.5 * 72, 11 * 7.2]); .Ve .Sp For other page or boundary sizes, the width and height (in points) can be given directly as an array. .ie n .IP "[$x1, $y1, $x2, $y2] in points" 4 .el .IP "[$x1, \f(CW$y1\fR, \f(CW$x2\fR, \f(CW$y2\fR] in points" 4 .IX Item "[$x1, $y1, $x2, $y2] in points" .Vb 1 \& $page\->boundaries(\*(Aqmedia\*(Aq => [0, 0, 8.5 * 72, 11 * 72]); .Ve .Sp Finally, the absolute (raw) coordinates of the bottom\-left and top\-right corners of a rectangle can be specified. .PP \fIPage Boundaries\fR .IX Subsection "Page Boundaries" .PP PDF defines five page boundaries. When creating PDFs for print shops, you\*(Aqll most commonly use just the media box and trim box. Traditional print shops may also use the bleed box when adding printer\*(Aqs marks and other information. .IP media 4 .IX Item "media" The media box defines the boundaries of the physical medium on which the page is to be printed. It may include any extended area surrounding the finished page for bleed, printing marks, or other such purposes. The default value is as defined for PDF, a US letter page (8.5" x 11"). \&\fBCAUTION:\fR Most printers can \fInot\fR print all the way to the edge of the physical medium (paper, etc.). Some space around the edges will be reserved for pinch rollers, etc. to move the paper without smearing around toner or ink. .IP crop 4 .IX Item "crop" The crop box defines the region to which the contents of the page shall be clipped (cropped) when displayed or printed. The default value is the page\*(Aqs media box. This is a historical page boundary. You\*(Aqll likely want to set the bleed and/or trim boxes instead. .IP bleed 4 .IX Item "bleed" The bleed box defines the region to which the contents of the page shall be clipped when output in a production environment. This may include any extra bleed area needed to accommodate the physical limitations of cutting, folding, and trimming equipment. The actual printed page (media box) may include printing marks that fall outside the bleed box. The default value is the page\*(Aqs crop box. .IP trim 4 .IX Item "trim" The trim box defines the intended dimensions of the finished page after trimming. It may be smaller than the media box to allow for production\-related content, such as printing instructions, cut marks, or color bars. The default value is the page\*(Aqs crop box. .IP art 4 .IX Item "art" The art box defines the extent of the page\*(Aqs meaningful content (including potential white space) as intended by the page\*(Aqs creator. The default value is the page\*(Aqs crop box. .PP \fIuserunit\fR .IX Subsection "userunit" .PP .Vb 1 \& $page\->userunit($value) .Ve .Sp .RS 4 Sets the User Unit for this one page. See "User Units" in PDF::Builder::Docs for more information. .RE .PP \fImediabox\fR .IX Subsection "mediabox" .PP .Vb 1 \& $page\->mediabox($alias) \& \& $page\->mediabox($alias, \*(Aqorient\*(Aq => \*(Aqorientation\*(Aq) \& \& $page\->mediabox($w,$h) \& \& $page\->mediabox($llx,$lly, $urx,$ury) \& \& ($llx,$lly, $urx,$ury) = $page\->mediabox() .Ve .Sp .RS 4 Sets or gets the Media Box for this one page. See "Media Box" in PDF::Builder::Docs for more information. The method always returns the current bounds (after any set operation). .RE .PP \fIcropbox\fR .IX Subsection "cropbox" .PP .Vb 1 \& $page\->cropbox($alias) \& \& $page\->cropbox($alias, \*(Aqorient\*(Aq => \*(Aqorientation\*(Aq) \& \& $page\->cropbox($w,$h) \& \& $page\->cropbox($llx,$lly, $urx,$ury) \& \& ($llx,$lly, $urx,$ury) = $page\->cropbox() .Ve .Sp .RS 4 Sets or gets the Crop Box for this one page. See "Crop Box" in PDF::Builder::Docs for more information. The method always returns the current bounds (after any set operation). .RE .PP \fIbleedbox\fR .IX Subsection "bleedbox" .PP .Vb 1 \& $page\->bleedbox($alias) \& \& $page\->bleedbox($alias, \*(Aqorient\*(Aq => \*(Aqorientation\*(Aq) \& \& $page\->bleedbox($w,$h) \& \& $page\->bleedbox($llx,$lly, $urx,$ury) \& \& ($llx,$lly, $urx,$ury) = $page\->bleedbox() .Ve .Sp .RS 4 Sets or gets or gets the Bleed Box for this one page. See "Bleed Box" in PDF::Builder::Docs for more information. The method always returns the current bounds (after any set operation). .RE .PP \fItrimbox\fR .IX Subsection "trimbox" .PP .Vb 1 \& $page\->trimbox($alias) \& \& $page\->trimbox($alias, \*(Aqorient\*(Aq => \*(Aqorientation\*(Aq) \& \& $page\->trimbox($w,$h) \& \& $page\->trimbox($llx,$lly, $urx,$ury) \& \& ($llx,$lly, $urx,$ury) = $page\->trimbox() .Ve .Sp .RS 4 Sets or gets the Trim Box for this one page. See "Trim Box" in PDF::Builder::Docs for more information. The method always returns the current bounds (after any set operation). .RE .PP \fIartbox\fR .IX Subsection "artbox" .PP .Vb 1 \& $page\->artbox($alias) \& \& $page\->artbox($alias, \*(Aqorient\*(Aq => \*(Aqorientation\*(Aq) \& \& $page\->artbox($w,$h) \& \& $page\->artbox($llx,$lly, $urx,$ury) \& \& ($llx,$lly, $urx,$ury) = $page\->artbox() .Ve .Sp .RS 4 Sets or gets the Art Box for this one page. See "Art Box" in PDF::Builder::Docs for more information. The method always returns the current bounds (after any set operation). .RE .PP \fIsize\fR .IX Subsection "size" .PP .Vb 1 \& $page\->size($size) # Set \& \& @rectangle = $page\->size() # Get .Ve .Sp .RS 4 Set the physical page size or return the coordinates of the rectangle enclosing the physical page size. This is an alternate method provided for compatibility with PDF::API2. .Sp .Vb 2 \& # Set the physical page (media) size using a common size name \& $page\->size(\*(Aqletter\*(Aq); \& \& # Set the page size using coordinates in points (X1, Y1, X2, Y2) \& $page\->size([0, 0, 612, 792]); \& \& # Get the page coordinates in points \& my @rectangle = $page\->size(); .Ve .Sp See Page Sizes above for possible values. The size method is a convenient shortcut for setting the PDF\*(Aqs media box when other prepress (print\-related) page boundaries aren\*(Aqt required. It\*(Aqs equivalent to the following: .Sp .Vb 2 \& # Set \& $page = $page\->boundaries(\*(Aqmedia\*(Aq => $size); \& \& # Get \& @rectangle = $page\->boundaries()\->{\*(Aqmedia\*(Aq}\->@*; .Ve .RE .PP \fIboundaries\fR .IX Subsection "boundaries" .PP .Vb 1 \& $page = $page\->boundaries(%boundaries) \& \& %boundaries = $page\->boundaries() .Ve .Sp .RS 4 Set prepress page boundaries to facilitate printing. Returns the current page boundaries if called without arguments. This is an alternate method provided for compatibility with PDF::API2. .Sp .Vb 9 \& # Set \& %boundaries = $page\->boundaries( \& # 13x19 inch physical sheet size \& \*(Aqmedia\*(Aq => \*(Aq13x19\*(Aq, \& # sheet content is 11x17 with 0.25" bleed \& \*(Aqbleed\*(Aq => [0.75 * 72, 0.75 * 72, 12.25 * 72, 18.25 * 72], \& # 11x17 final trimmed size \& \*(Aqtrim\*(Aq => 0.25 * 72, \& ); .Ve .Sp The \f(CW%boundaries\fR hash contains one or more page boundary keys (see Page Boundaries) to set or replace, each with a corresponding size (see Page Sizes). The resulting boundaries hash will be returned. .Sp .Vb 3 \& # Get \& %boundaries = $page\->boundaries(); \& ($x1,$y1, $x2,$y2) = $page\->boundaries(\*(Aqtrim\*(Aq); .Ve .Sp If called without arguments, the returned hashref will contain (Get) all five boundaries. If called with one string argument, it returns the coordinates for the specified page (media, crop, bleed, trim, or art) boundary. If more than one boundary type is given, only the first is processed, and a warning is given that the remainder are ignored. .RE .SS "Page Operation Methods" .IX Subsection "Page Operation Methods" \fIgfx, graphics\fR .IX Subsection "gfx, graphics" .PP .Vb 1 \& $gfx = $page\->gfx(%opts) \& \& $gfx = $page\->gfx($prepend) \& \& $gfx = $page\->gfx() .Ve .Sp .RS 4 Returns a graphics content object, for drawing paths and shapes. .Sp You may specify the "prepend" flag in the old or new way. The old way is to give a single boolean value (0 false, non\-zero true). The new way is to give a hash element named \*(Aqprepend\*(Aq, with the same values. .ie n .IP "gfx(boolean_value $prepend)" 4 .el .IP "gfx(boolean_value \f(CW$prepend\fR)" 4 .IX Item "gfx(boolean_value $prepend)" .PD 0 .IP "gfx(\*(Aqprepend\*(Aq => boolean_value)" 4 .IX Item "gfx('prepend' => boolean_value)" .PD .RE .RS 4 .Sp If \f(CW$prepend\fR is \fItrue\fR, or the option \*(Aqprepend\*(Aq is given with a \fItrue\fR value, the content will be prepended to the page description (at the beginning of the page\*(Aqs content stream). Otherwise, it will be appended. The default is \fIfalse\fR. .IP "gfx(\*(Aqcompress\*(Aq => boolean_value)" 4 .IX Item "gfx('compress' => boolean_value)" .RE .RS 4 .Sp You may specify a compression flag saying whether the drawing instructions are to be compressed. If not given, the default is for the overall PDF compression setting to be used (\fIon\fR by default). .Sp You may have more than one \fIgfx\fR object. They and \fItext\fR objects will be output as objects and streams \fIin the order \fR\f(BIthat the objects are\fR\fI defined\fR, with all actions pertaining to this \fIgfx\fR object appearing in one stream. However, note that graphics and text objects are not fully independent of each other: the exit state (linewidth, strokecolor, etc.) of one object is the entry state of the next object in line to be output, and so on. .Sp If you intermix multiple \fIgfx\fR and \fItext\fR objects on a page, the results may be confusing. Say you have \f(CW$gfx1\fR, \f(CW$text1\fR, \f(CW$gfx2\fR, and \&\f(CW$text2\fR on your page (\fIcreated in that order\fR). PDF::Builder will output all the \&\f(CW$gfx1\fR\->\fIaction\fR calls in one stream, then all the \f(CW$text1\fR\->\fIaction\fR calls in the next stream, and likewise for \f(CW$gfx2\fR usage and finally \f(CW$text2\fR. .Sp Then it\*(Aqs PDF\*(Aqs turn to confuse you. PDF will process the entire \f(CW$gfx1\fR object stream, accumulating the graphics state to the end of the stream, and using that as the entry state into \f(CW$text1\fR. In a similar manner, \f(CW$gfx2\fR and \f(CW$text2\fR are read, processed, and rendered. Thus, a change in, say, the dash pattern in the middle of \f(CW$gfx1\fR, \fIafter\fR you have output some \f(CW$gfx2\fR, \f(CW$text1\fR, and \f(CW$text2\fR material, may suddenly show up at the beginning of \f(CW$text1\fR (and continue through \&\f(CW$gfx2\fR and \f(CW$text2\fR)! .Sp It is possible to use multiple graphics objects, to avoid having to change settings constantly, but you may want to consider resetting all your settings at the first call to each object, so that you are starting from a known base. This may most easily be done by using $\fItype\fR\->\fBrestore()\fR and \->\fBsave()\fR just after creating $\fItype\fR: .Sp .Vb 10 \& $text1 = $page\->text(); \& $text1\->save(); \& $grfx1 = $page\->gfx(); \& $grfx1\->restore(); \& $grfx1\->save(); \& $text2 = $page\->text(); \& $text2\->restore(); \& $text2\->save(); \& $grfx2 = $page\->gfx(); \& $grfx1\->restore(); .Ve .Sp \&\fIGenerally,\fR you will want to define the graphics object first, and then the text object after that. This defines the order in which the streams will be rendered (graphics first), which is usually desirable if you\*(Aqre setting a background color, or have other graphics with which you want to overlay text over. Sometimes, though, you may wish to overlay text with graphics, in which case you might either define the objects text and then graphics, or define a second graphics stream to lay over the text. Most of the time it really doesn\*(Aqt matter which comes first (as text and graphics don\*(Aqt interact or overlay), but in any case, be aware of states carried over from the end of one stream into the next. .Sp \&\fBAlternate name:\fR \f(CW\*(C`graphics\*(C'\fR .Sp This has been added for PDF::API2 compatibility. .RE .PP \fItext\fR .IX Subsection "text" .PP .Vb 1 \& $text = $page\->text(%opts) \& \& $text = $page\->text($prepend) \& \& $text = $page\->text() .Ve .Sp .RS 4 Returns a text content object, for writing text. See PDF::Builder::Content for details. .Sp You may specify the "prepend" flag in the old or new way. The old way is to give a single boolean value (0 false, non\-zero true). The new way is to give a hash element named \*(Aqprepend\*(Aq, with the same values. .ie n .IP "text(boolean_value $prepend)" 4 .el .IP "text(boolean_value \f(CW$prepend\fR)" 4 .IX Item "text(boolean_value $prepend)" .PD 0 .IP "text(\*(Aqprepend\*(Aq => boolean_value)" 4 .IX Item "text('prepend' => boolean_value)" .PD .RE .RS 4 .Sp If \f(CW$prepend\fR is \fItrue\fR, or the option \*(Aqprepend\*(Aq is given with a \fItrue\fR value, the content will be prepended to the page description (at the beginning of the page\*(Aqs content stream). Otherwise, it will be appended. The default is \fIfalse\fR. .IP "text(\*(Aqcompress\*(Aq => boolean_value)" 4 .IX Item "text('compress' => boolean_value)" .RE .RS 4 .Sp You may specify a compression flag saying whether the text content is to be compressed. If not given, the default is for the overall PDF compression setting to be used (\fIon\fR by default). .Sp Please see the discussion above in \f(CWgfx()\fR regarding multiple graphics and text objects on one page, how they are grouped into PDF objects and streams, and the rendering consequences of running through one entire object (stream) at a time, before moving on to the next. Even if you have only one graphics and one text stream, the order in which they are defined has consequences for how text overlays graphics or vice\-versa. .Sp The \fItext\fR object has many settings and attributes of its own, but shares many with graphics (\fIgfx\fR), such as strokecolor, fillcolor, linewidth, linedash, and the like. Thus there is some overlap in attributes, and graphics and text calls can affect each other. .RE .PP \fIrotate, rotation\fR .IX Subsection "rotate, rotation" .PP .Vb 1 \& $page\->rotate($deg) .Ve .Sp .RS 4 Rotates the page by the given degrees, which must be a multiple of 90. An angle that is not a multiple of 90 will be rounded to the nearest 90 degrees, with a message. .Sp Note that the rotation angle is \fIclockwise\fR for a positive amount! E.g., a rotation of +90 (or \-270) will have the bottom edge of the paper at the left of the screen. After rotating the page 180 degrees, \f(CW\*(C`[0, 0]\*(C'\fR (originally lower left corner) will be be in the top right corner of the page, rather than the bottom left. X will increase to the right, and Y will increase downward. .Sp (This allows you to auto\-rotate to landscape without changing the mediabox! There are other ways to accomplish this end, such as using the \f(CWsize()\fR method, which will not change the coordinate system (move the origin).) .Sp \&\fBNote\fR that some users have reported problems with using \f(CW\*(C`rotate\*(C'\fR, that the dimensions were limited to the smaller of the original height or width. If you experience this, be sure to check whether you are doing some sort of \fIcrop box\fR or other clipping, that might not rotate as expected with the rest of the page. In other words, you might need to manually adjust the crop box dimensions. .Sp Do not confuse this \f(CWrotate()\fR call with the \fIgraphics context\fR rotation (Content.pm) \f(CWrotate()\fR, which permits any angle, is of opposite direction, and does not shift the origin! .Sp \&\fBAlternate name:\fR \f(CW\*(C`rotation\*(C'\fR .Sp This has been added for PDF::API2 compatibility. .RE .PP \fIobject\fR .IX Subsection "object" .PP .Vb 1 \& $page = $page\->object($object, $x,$y, $scale_x,$scale_y) .Ve .Sp .RS 4 Places an image or other external object (a.k.a. XObject) on the page in the specified location. .Sp If \f(CW$x\fR and \f(CW$y\fR are omitted, the object will be placed at \f(CW\*(C`[0, 0]\*(C'\fR. .Sp For images, \f(CW$scale_x\fR and \f(CW$scale_y\fR represent the width and height of the image on the page in points. If \f(CW$scale_x\fR is omitted, it will default to 72 pixels per inch. If \f(CW$scale_y\fR is omitted, the image will be scaled proportionally based on the image dimensions. .Sp For other external objects, the scale is a multiplier, where 1 (the default) represents 100% (i.e. no change). .Sp If the object to be placed depends on a coordinate transformation (e.g. rotation or skew), first create a content object using "graphics", then call "object" in PDF::Builder::Content after making the appropriate transformations. .RE .PP \fIannotation\fR .IX Subsection "annotation" .PP .Vb 1 \& $ant = $page\->annotation() .Ve .Sp .RS 4 Returns a new annotation object. .RE .PP \fIresource\fR .IX Subsection "resource" .PP .Vb 1 \& $page\->resource($type, $key, $obj) .Ve .Sp .RS 4 Adds a resource to the page\-inheritance tree. .Sp \&\fBExample:\fR .Sp .Vb 4 \& $co\->resource(\*(AqFont\*(Aq, $fontkey, $fontobj); \& $co\->resource(\*(AqXObject\*(Aq, $imagekey, $imageobj); \& $co\->resource(\*(AqShading\*(Aq, $shadekey, $shadeobj); \& $co\->resource(\*(AqColorSpace\*(Aq, $spacekey, $speceobj); .Ve .Sp \&\fBNote:\fR You only have to add the required resources if they are NOT handled by the *font*, *image*, *shade* or *space* methods. .RE