Table of contents
Namespace: Com\Tecnick\Pdf\Import
class PageResolver
Source: src/Import/PageResolver.php:51
Traverses the PDF page tree and returns the effective page dictionary with all inherited attributes (MediaBox, CropBox, Rotate, Resources …) resolved for a 1-based page number.
Types
PageBox
array{0: float, 1: float, 2: float, 3: float}
ResolvedPage
array{
'dict': array<string, mixed>,
'mediaBox': PageBox,
'cropBox': PageBox,
'bleedBox': PageBox,
'trimBox': PageBox,
'artBox': PageBox,
'rotate': int,
'resources': array<string, mixed>,
}
Constants
MAX_PAGE_TREE_NODES
Hard ceiling on page tree nodes visited in a single walk, on top of the duplicate-reference guard that bounds every walk by the number of distinct objects in the source file.
public const MAX_PAGE_TREE_NODES = 1000000
Source: src/Import/PageResolver.php:65
Methods
__construct()
Constructor.
public __construct()
Source: src/Import/PageResolver.php:75
buildPageIndex()
Build the flattened page index: one effective page dictionary (the page’s own entries merged over the attributes inherited from its ancestor /Pages nodes) per reachable page, in document order.
The walk is iterative, visits every node exactly once (a global visited set rejects duplicate and cyclic references) and is bounded by $maxNodes. The declared /Count entry is ignored: it is controlled by the source file and never sizes an allocation or bounds a loop.
public buildPageIndex(SourceDocument $src, int $maxNodes = \self::MAX_PAGE_TREE_NODES): array<int,array<string,mixed>>
Parameters:
$src(SourceDocument): Parsed source document.$maxNodes(int): Maximum number of tree nodes to visit.
Returns: array<int,array<string,mixed>>: Effective page dictionaries in document order.
Throws:
- ImportCorruptedSourceException: If the page tree is malformed, contains duplicate or cyclic references, or exceeds the node budget.
Source: src/Import/PageResolver.php:152
countPages()
Count the pages actually reachable through the /Kids page tree.
The declared /Count entry of the /Pages dictionary is ignored: it is controlled by the source file and never sizes an allocation or bounds a loop. The walk applies the same acceptance rules as resolve(), so both methods agree on which pages are reachable.
public countPages(SourceDocument $src, int $maxNodes = \self::MAX_PAGE_TREE_NODES): int
Parameters:
$src(SourceDocument): Parsed source document.$maxNodes(int): Maximum number of tree nodes to visit.
Returns: int: Number of reachable pages.
Throws:
- ImportCorruptedSourceException: If the page tree is malformed, contains duplicate or cyclic references, or exceeds the node budget.
Source: src/Import/PageResolver.php:234
resolve()
Resolve the effective page dictionary for the given 1-based page number.
Convenience wrapper that builds the page index and resolves from it. Callers importing many pages from the same source should build the index once with buildPageIndex() and use resolveFromIndex(), so the page tree is walked only once per source.
public resolve(SourceDocument $src, int $pageNum): array<string,mixed>
Parameters:
$src(SourceDocument): Parsed source document.$pageNum(int): 1-based page number to resolve.
Returns: array<string,mixed>
Throws:
- ImportPageOutOfRangeException: If the page number is out of range.
- ImportCorruptedSourceException: If the page tree is malformed.
Source: src/Import/PageResolver.php:97
resolveFromIndex()
Resolve a page against a page index previously built by buildPageIndex().
public resolveFromIndex(
SourceDocument $src,
array<int,array<string,mixed>> $index,
int $pageNum
): array<string,mixed>
Parameters:
$src(SourceDocument): Parsed source document the index was built from.$index(array<int,array<string,mixed>>): Flattened page index in document order.$pageNum(int): 1-based page number to resolve.
Returns: array<string,mixed>
Throws:
- ImportPageOutOfRangeException: If the page number is out of range.
- ImportCorruptedSourceException: If page boxes or resources are malformed.
Source: src/Import/PageResolver.php:119