API reference / Quittio \ Core \ Pdf
PdfEmbeddedFileExtractor
final class in quittio/core · implements DiagnosingXmlExtractor
Quittio\Core\Pdf\PdfEmbeddedFileExtractor · Source
Extracts the embedded invoice XML from PDF files (ZUGFeRD 2.x, Factur-X, XRechnung in PDF).
Embedded files are searched in the associated files of the document (/AF, PDF/A-3) and in the name tree (/Names /EmbeddedFiles). Classic cross-reference tables, cross-reference streams and object streams are supported. All structures are limited (tree size, number of file specifications, decompressed size) as protection against malicious files, and file names are never used as paths.
Constants#
| Constant | Value | Description |
|---|---|---|
KNOWN_FILENAMES | ['factur-x.xml', 'xrechnung.xml', 'zugferd-invoice.xml', 'ZUGFeRD-invoice.xml'] | Known file names in order of preference (ZUGFeRD-invoice.xml is the ZUGFeRD 1.0 name). |
Methods#
| Method | Description |
|---|---|
->__construct() | |
->extract() | |
->extractFile() | The embedded invoice XML with its file name, /AFRelationship and findings (several candidates with different content, a file that is no associated file), or null if the PDF embeds no XML file. Known file names win over other XML files, associated files (/AF) over name tree entries. Throws a PdfException when the PDF is too large, malformed or exceeds a limit. |
->maxPdfBytes() | Largest PDF in bytes the extractor accepts; larger input throws a PdfException. InvoiceReader::readFile() accepts files up to this size as well. |
->names() | Names of all embedded files. |
__construct()#
public function __construct(
int $maxPdfBytes = 25 * 1024 * 1024,
int $maxDecompressedBytes = 50 * 1024 * 1024,
)| Parameter | Type | Description |
|---|---|---|
$maxPdfBytes | int = 25 * 1024 * 1024 | |
$maxDecompressedBytes | int = 50 * 1024 * 1024 |
extract()#
public function extract(string $pdf): ?array| Parameter | Type | Description |
|---|---|---|
$pdf | string |
- Returns
?array
extractFile()#
public function extractFile(string $pdf): ?ExtractedXmlThe embedded invoice XML with its file name, /AFRelationship and findings (several candidates with different content, a file that is no associated file), or null if the PDF embeds no XML file. Known file names win over other XML files, associated files (/AF) over name tree entries. Throws a PdfException when the PDF is too large, malformed or exceeds a limit.
| Parameter | Type | Description |
|---|---|---|
$pdf | string |
- Returns
?ExtractedXml
maxPdfBytes()#
public function maxPdfBytes(): intLargest PDF in bytes the extractor accepts; larger input throws a PdfException. InvoiceReader::readFile() accepts files up to this size as well.
- Returns
int
names()#
public function names(string $pdf): list<string>Names of all embedded files.
| Parameter | Type | Description |
|---|---|---|
$pdf | string |
- Returns
list<string>