Table of contents
Namespace: Com\Tecnick\Pdf\Import
Implements: ImporterInterface
File: Importer.php line 50
Orchestrates PDF import: loads source documents, resolves pages, clones resources, builds Form XObjects, and registers them for deferred output via getOutImportedObjects().
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: TXOBject from \Com\Tecnick\Pdf\Base
- phpstan-type: ImportOptions array{ box?: string, respectRotation?: bool, groupXObject?: bool, cache?: bool, }
- SuppressWarnings: (“CouplingBetweenObjects”)
Methods
__construct()
File: Importer.php line 148
public __construct(array<string, mixed> &$xobjects, int &$pon, File $file[, int $pdfa = 0 ][, Encrypt|null $encrypt = null ][, bool $requireEmbeddedFonts = false ]) : mixed
Parameters
- $xobjects : array<string, mixed>: Reference to the destination document’s xobjects array.
- $pon : int: Reference to the PDF object number counter.
- $file : File: Shared file helper instance.
- $pdfa : int = 0: PDF/A part of the destination document (0 when not active).
- $encrypt : Encrypt|null = null: Encryption object of the destination document; a disabled one is used when null.
- $requireEmbeddedFonts : bool = false: True when the destination document requires every font to be embedded.
Tags
- throws: Exception
cleanUp()
File: Importer.php line 495
public cleanUp() : void
Should be called after getOutImportedObjects() completes.
getOutImportedObjects()
File: Importer.php line 480
public getOutImportedObjects() : string
Called from getOutPDFBody() after getOutXObjects().
Return values
string —
Serialized PDF object bytes.
getSourcePageCount()
File: Importer.php line 278
public getSourcePageCount(string $sourceId) : int
The count is derived from the page tree reachable through /Kids. The declared /Count entry is ignored: it is controlled by the source file and never sizes an allocation or bounds a loop.
Parameters
- $sourceId : string: Source document identifier.
Tags
- throws: ImportSourceNotFoundException If the source ID is not registered.
- throws: ImportCorruptedSourceException If the page tree is malformed.
Return values
int —
Total page count.
getWarnings()
File: Importer.php line 171
public getWarnings() : array<int, string>
Return values
array<int, string>
importPage()
File: Importer.php line 299
public importPage(string $sourceId, int $pageNum[, array<string, mixed> $options = [] ]) : PageTemplateInterface
Parameters
- $sourceId : string: Source document identifier.
- $pageNum : int: 1-based page number.
- $options : array<string, mixed> = []: Import options (box, groupXObject, cache, respectRotation).
Tags
- throws: ImportSourceNotFoundException If the source ID is not registered.
- throws: ImportPageOutOfRangeException If the page number is out of range.
- throws: ImportCorruptedSourceException If the page tree is malformed.
- throws: ImportException If object mapping or cloning fails.
- throws: ImportUnsupportedFeatureException If an unsupported feature is encountered.
- throws: Exception
Return values
Imported page template.
importPages()
File: Importer.php line 444
public importPages(string $sourceId[, array<string|int, int>|null $range = null ][, array<string, mixed> $options = [] ]) : array<int, PageTemplateInterface>
Parameters
- $sourceId : string: Source document identifier.
- $range : array<string|int, int>|null = null: 1-based page numbers to import, or null to import all pages.
- $options : array<string, mixed> = []: Import options (same as importPage).
Tags
- throws: ImportSourceNotFoundException If the source ID is not registered.
- throws: ImportPageOutOfRangeException If any page number is out of range.
- throws: ImportCorruptedSourceException If the page tree is malformed.
- throws: ImportException If object mapping or cloning fails.
- throws: ImportUnsupportedFeatureException If an unsupported feature is encountered.
- throws: Exception
Return values
array<int, PageTemplateInterface> —
Indexed array of PageTemplate, one per requested page.
setImportSourceData()
File: Importer.php line 252
public setImportSourceData(string $data[, array<string, mixed> $cfg = [] ]) : string
Parameters
- $data : string: Raw PDF binary data.
- $cfg : array<string, mixed> = []: Optional parser configuration.
Tags
- throws: ImportCorruptedSourceException If the data cannot be parsed.
- throws: ImportUnsupportedFeatureException If the source is encrypted.
Return values
string —
Source document identifier (SHA-256 of the data).
setImportSourceFile()
File: Importer.php line 221
public setImportSourceFile(string $path[, array<string, mixed> $cfg = [] ]) : string
Parameters
- $path : string: File path to a readable PDF.
- $cfg : array<string, mixed> = []: Optional parser configuration.
Tags
- throws: ImportSourceNotFoundException If the file cannot be read.
- throws: ImportCorruptedSourceException If the file cannot be parsed.
- throws: ImportUnsupportedFeatureException If the source is encrypted.
Return values
string —
Source document identifier.