[Raku PDF Project] / [PDF-Content Module] / PDF::Content :: PageTree
methods related to page tree nodes
This role contains methods for querying and manipulating page tree nodes in a PDF.
This class includes the methods:
page-fragment
- create a detached page
pages-fragment
- create a detached page sub-tree
`global-resources-scope - get or set shared resources across pages
These stand-alone fragments aim to be thread-safe to support parallel construction of pages. The final PDF assembly needs to be synchronous.
use PDF::Content::Page;
use PDF::Content::PageTree;
use lib 't';
use PDFTiny;
my PDFTiny $pdf .= new;
my PDF::Content::Page @pages;
@pages = (1..20).hyper(:batch(1)).map: -> $page-num {
my PDF::Content::Page:D $page = PDF::Content::PageTree.page-fragment;
$page.text: {
.text-position = 50, 400;
.say: "Page $page-num";
}
$page.finish;
$page;
}
$pdf.add-page($_) for @pages;
method page-fragment() returns PDF::Content::Page
produce a single page fragment, not attached to any PDF
method pages-fragment() returns PDF::Content::PageNode
produce a page-tree fragment, not attached to any PDF
method global-resources-scope() returns Bool
get or set global-resources-scope
This is an advanced setting that sets up a global resource dictionary. Any pages that are then directly created via add-page
will use the global resources dictionary for fonts and XObjects, etc. This may be of use in certain specialized cases, such as when the PDF is being used as a resource library. The resources will be able to be accessed later by opening the PDF, but without needing to go to any particular page.
method add-page(
PDF::Content::Page:D $page = Code.new
) returns PDF::Content::Page
add new last page
method add-pages(
PDF::Content::PageTree:D $pages = Code.new
) returns PDF::Content::PageTree
append page subtree
method page(
Int $page-num where { ... } = 0
) returns PDF::Content::Page
$.page(0?) - adds a new page
method page(
Int $page-num where { ... }
) returns PDF::Content::Page
traverse page tree
method page-index() returns Array
build flattened index of indirect references to pages
method pages() returns Array
return all leaf pages for this page tree. or sub-tree
method delete-page(
Int $page-num where { ... }
) returns PDF::Content::Page
delete page from page tree
method page-count() returns UInt
return the number of pages