NAME
PDF::Builder::Page - Methods to interact with individual pages
METHODS
- $page = PDF::Builder::Page->new($pdf, $parent, $index)
-
Returns a page object (called from $pdf->page()).
- $page->userunit($value)
-
Sets the User Unit for this one page. See "User Units" in PDF::Builder::Docs for more information.
- $page->mediabox($alias)
- $page->mediabox($alias, -orient => 'orientation')
- $page->mediabox($w,$h)
- $page->mediabox($llx,$lly, $urx,$ury)
- ($llx,$lly, $urx,$ury) = $page->mediabox()
-
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).
- ($llx,$lly, $urx,$ury) = $page->get_mediabox()
-
Gets the Media Box corner coordinates based on best estimates or the default. These are in the order given in a mediabox call (4 coordinates).
This method is Deprecated, and will likely be removed in the future. Use the global (
$pdf
) or page ($page
) mediabox() call with no parameters instead. - $page->cropbox($alias)
- $page->cropbox($alias, -orient => 'orientation')
- $page->cropbox($w,$h)
- $page->cropbox($llx,$lly, $urx,$ury)
- ($llx,$lly, $urx,$ury) = $page->cropbox()
-
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).
- ($llx,$lly, $urx,$ury) = $page->get_cropbox()
-
Gets the Crop Box based on best estimates or the default.
This method is Deprecated, and will likely be removed in the future. Use the global (
$pdf
) or page ($page
) cropbox() call with no parameters instead. - $page->bleedbox($alias)
- $page->bleedbox($alias, -orient => 'orientation')
- $page->bleedbox($w,$h)
- $page->bleedbox($llx,$lly, $urx,$ury)
- ($llx,$lly, $urx,$ury) = $page->bleedbox()
-
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).
- ($llx,$lly, $urx,$ury) = $page->get_bleedbox()
-
Gets the Bleed Box based on best estimates or the default.
This method is Deprecated, and will likely be removed in the future. Use the global (
$pdf
) or page ($page
) bleedbox() call with no parameters instead. - $page->trimbox($alias)
- $page->trimbox($alias, -orient => 'orientation')
- $page->trimbox($w,$h)
- $page->trimbox($llx,$lly, $urx,$ury)
- ($llx,$lly, $urx,$ury) = $page->trimbox()
-
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).
- ($llx,$lly, $urx,$ury) = $page->get_trimbox()
-
Gets the Trim Box based on best estimates or the default.
This method is Deprecated, and will likely be removed in the future. Use the global (
$pdf
) or page ($page
) trimbox() call with no parameters instead. - $page->artbox($alias)
- $page->artbox($alias, -orient => 'orientation')
- $page->artbox($w,$h)
- $page->artbox($llx,$lly, $urx,$ury)
- ($llx,$lly, $urx,$ury) = $page->artbox()
-
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).
- ($llx,$lly, $urx,$ury) = $page->get_artbox()
-
Gets the Art Box based on best estimates or the default.
This method is Deprecated, and will likely be removed in the future. Use the global (
$pdf
) or page ($page
) artbox() call with no parameters instead. - $page->rotate($deg)
-
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. Note that the rotation angle is clockwise 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.
(This allows you to auto-rotate to landscape without changing the mediabox!)
- $gfx = $page->gfx($prepend)
- $gfx = $page->gfx()
-
Returns a graphics content object. If $prepend is true, the content will be prepended to the page description. Otherwise, it will be appended.
You may have more than one gfx object. They and text objects will be output as objects and streams in the order defined, with all actions pertaining to this gfx 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.
If you intermix multiple gfx and text objects on a page, the results may be confusing. Say you have $gfx1, $text1, $gfx2, and $text2 on your page (created in that order). PDF::Builder will output all the $gfx1->action calls in one stream, then all the $text1->action calls in the next stream, and likewise for $gfx2 usage and finally $text2.
Then it's PDF's turn to confuse you. PDF will process the entire $gfx1 object stream, accumulating the graphics state to the end of the stream, and using that as the entry state into $text1. In a similar manner, $gfx2 and $text2 are read, processed, and rendered. Thus, a change in, say, the dash pattern in the middle of $gfx1, after you have output some $gfx2, $text1, and $text2 material, may suddenly show up at the beginning of $text1 (and continue through $gfx2 and $text2)!
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 $type->restore() and ->save() just after creating $type:
$text1 = $page->text(); $text1->save(); $grfx1 = $page->gfx(); $grfx1->restore(); $grfx1->save(); $text2 = $page->text(); $text2->restore(); $text2->save(); $grfx2 = $page->gfx(); $grfx1->restore();
- $txt = $page->text($prepend)
- $txt = $page->text()
-
Returns a text content object. If $prepend is true, the content will be prepended to the page description. Otherwise, it will be appended.
Please see the discussion above in
gfx()
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 at a time, before moving on to the next.The text object has many settings and attributes of its own, but shares many with graphics (gfx), 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.
- $ant = $page->annotation()
-
Returns a new annotation object.
- $page->resource($type, $key, $obj)
-
Adds a resource to the page-inheritance tree.
Example:
$co->resource('Font', $fontkey, $fontobj); $co->resource('XObject', $imagekey, $imageobj); $co->resource('Shading', $shadekey, $shadeobj); $co->resource('ColorSpace', $spacekey, $speceobj);
Note: You only have to add the required resources if they are NOT handled by the *font*, *image*, *shade* or *space* methods.