PageResolver

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.

Namespace: Com\Tecnick\Pdf\Import

File: PageResolver.php line 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.

Tags

  • since: 2026-05-03
  • category: Library
  • author: Nicola Asuni info@tecnick.com
  • copyright: 2002-2026 Nicola Asuni - Tecnick.com LTD
  • license: https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE)
  • link: https://github.com/tecnickcom/tc-lib-pdf
  • phpstan-import-type: RawObjectArray from \Com\Tecnick\Pdf\Parser\Process\RawObject
  • phpstan-type: PageBox array{0: float, 1: float, 2: float, 3: float}
  • phpstan-type: 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

File: PageResolver.php line 65

public mixed MAX_PAGE_TREE_NODES = 1000000

Methods

__construct()

File: PageResolver.php line 75

public __construct() : mixed

buildPageIndex()

File: PageResolver.php line 152

public buildPageIndex(SourceDocument $src[, int $maxNodes = self::MAX_PAGE_TREE_NODES ]) : array<int, array<string, mixed>>

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.

Parameters

  • $src : SourceDocument: Parsed source document.
  • $maxNodes : int = self::MAX_PAGE_TREE_NODES: Maximum number of tree nodes to visit.

Tags

Return values

array<int, array<string, mixed» —

Effective page dictionaries in document order.

countPages()

File: PageResolver.php line 232

public countPages(SourceDocument $src[, int $maxNodes = self::MAX_PAGE_TREE_NODES ]) : int

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.

Parameters

  • $src : SourceDocument: Parsed source document.
  • $maxNodes : int = self::MAX_PAGE_TREE_NODES: Maximum number of tree nodes to visit.

Tags

Return values

int —

Number of reachable pages.

resolve()

File: PageResolver.php line 97

public resolve(SourceDocument $src, int $pageNum) : array<string, mixed>

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.

Parameters

  • $src : SourceDocument: Parsed source document.
  • $pageNum : int: 1-based page number to resolve.

Tags

Return values

array<string, mixed>

resolveFromIndex()

File: PageResolver.php line 119

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.

Tags

Return values

array<string, mixed>