Importer

Orchestrates PDF import: loads source documents, resolves pages, clones resources, builds Form XObjects, and registers them for deferred output via getOutImportedObjects().

Namespace: Com\Tecnick\Pdf\Import

class Importer implements ImporterInterface

Implements: ImporterInterface

Source: src/Import/Importer.php:59

Orchestrates PDF import: loads source documents, resolves pages, clones resources, builds Form XObjects, and registers them for deferred output via getOutImportedObjects().

Types

ImportOptions

array{
    box?:           string,
    respectRotation?: bool,
    groupXObject?:  bool,
    cache?:         bool,
}

ParserOptions

array{
    ignore_filter_errors?: bool,
    decode_streams?:       bool,
    strict_limits?:        bool,
    max_stream_size?:      int,
    max_resolution_depth?: int,
    max_nesting_depth?:    int,
}

Methods

__construct()

Constructor.

public __construct(
    array<string,mixed> &$xobjects,
    int &$pon,
    File $file,
    int $pdfa = 0,
    ?Encrypt $encrypt = null,
    bool $requireEmbeddedFonts = false
)

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): PDF/A part of the destination document (0 when not active).
  • $encrypt (?Encrypt): Encryption object of the destination document; a disabled one is used when null.
  • $requireEmbeddedFonts (bool): True when the destination document requires every font to be embedded.

Throws:

Source: src/Import/Importer.php:157

cleanUp()

Release parser memory and cached resources.

Should be called after getOutImportedObjects() completes.

public cleanUp(): void

Source: src/Import/Importer.php:579

getOutImportedObjects()

Flush all queued raw PDF objects to the output stream.

Called from getOutPDFBody() after getOutXObjects().

public getOutImportedObjects(): string

Returns: string: Serialized PDF object bytes.

Source: src/Import/Importer.php:564

getSourcePageCount()

Return the total number of pages in a registered source document.

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.

public getSourcePageCount(string $sourceId): int

Parameters:

  • $sourceId (string): Source document identifier.

Returns: int: Total page count.

Throws:

Source: src/Import/Importer.php:359

getWarnings()

Return the conformance warnings raised while pages were imported.

public getWarnings(): array<int,string>

Returns: array<int,string>

Source: src/Import/Importer.php:180

importPage()

Import one page from a registered source document and return a PageTemplate.

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).

Returns: PageTemplateInterface: Imported page template.

Throws:

Source: src/Import/Importer.php:380

importPages()

Import a range of pages from a registered source document.

public importPages(
    string $sourceId,
    int[]|null $range = null,
    array<string,mixed> $options = []
): array<int,PageTemplateInterface>

Parameters:

  • $sourceId (string): Source document identifier.
  • $range (int[]|null): 1-based page numbers to import, or null to import all pages.
  • $options (array<string,mixed>): Import options (same as importPage).

Returns: array<int,PageTemplateInterface>: Indexed array of PageTemplate, one per requested page.

Throws:

Source: src/Import/Importer.php:528

setImportSourceData()

Register a source PDF from raw binary data.

public setImportSourceData(string $data, array<string,mixed> $cfg = []): string

Parameters:

  • $data (string): Raw PDF binary data.
  • $cfg (array<string,mixed>): Optional parser configuration.

Returns: string: Source document identifier (SHA-256 of the data).

Throws:

Source: src/Import/Importer.php:315

setImportSourceFile()

Register a source PDF file.

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.

Returns: string: Source document identifier.

Throws:

Source: src/Import/Importer.php:280