Skip to content

API reference / Quittio \ Core \ Reading

InvoiceReader

final class in quittio/core

Quittio\Core\Reading\InvoiceReader · Source

Reads e-invoices from XML or PDF.

Detects the syntax and profile, keeps the declared totals and reports differences to a recalculation instead of correcting them silently.

Constants#

ConstantValueDescription
NS_ZUGFERD_1'urn:ferd:CrossIndustryDocument:invoice:1p0'Namespace of ZUGFeRD 1.0, which is recognised but not supported.

Methods#

MethodDescription
->__construct()
::defaultReaders()
->read()Reads the content (bytes) of an XML or PDF e-invoice.
->readFile()Reads an XML or PDF e-invoice from a local file.
->withReader()A copy that also tries $reader after the readers so far, e.g. for a national format.

__construct()#

public function __construct(
    list<FormatReader>|null $readers = null,
    ?ProfileRegistry $profiles = null,
    TotalsCalculator $calculator = new \Quittio\Core\Calculation\En16931Calculator(),
    EmbeddedXmlExtractor $pdfExtractor = new \Quittio\Core\Pdf\PdfEmbeddedFileExtractor(),
    int $maxXmlBytes = \Quittio\Core\Xml\XmlSecurity::DEFAULT_MAX_BYTES,
)
ParameterTypeDescription
$readerslist<FormatReader>|null = null
$profiles?ProfileRegistry = null
$calculatorTotalsCalculator = new \Quittio\Core\Calculation\En16931Calculator()
$pdfExtractorEmbeddedXmlExtractor = new \Quittio\Core\Pdf\PdfEmbeddedFileExtractor()
$maxXmlBytesint = \Quittio\Core\Xml\XmlSecurity::DEFAULT_MAX_BYTES

defaultReaders()#

public static function defaultReaders(): list<FormatReader>

static

Returns
list<FormatReader>

read()#

public function read(string $content): ReadResult

Reads the content (bytes) of an XML or PDF e-invoice.

The argument is always treated as content, never as a file name; use readFile() for paths.

ParameterTypeDescription
$contentstring
Returns
ReadResult
Throws
UnsafeXmlException – when the XML is too large, not well-formed or not allowed (DOCTYPE, limits)
Throws
PdfException – when the PDF is too large, encrypted, malformed or exceeds a limit
Throws
UnreadableInvoiceException – for an unknown format, ZUGFeRD 1.0 or a PDF without an embedded invoice

readFile()#

public function readFile(string $path): ReadResult

Reads an XML or PDF e-invoice from a local file.

ParameterTypeDescription
$pathstring
Returns
ReadResult
Throws
UnsafeXmlException – when the XML is too large, not well-formed or not allowed (DOCTYPE, limits)
Throws
PdfException – when the PDF is too large, encrypted, malformed or exceeds a limit
Throws
UnreadableInvoiceException – for an unknown format, ZUGFeRD 1.0, a PDF without an embedded invoice, or a file that does not exist, is not readable or is too large

withReader()#

public function withReader(FormatReader $reader): self

A copy that also tries $reader after the readers so far, e.g. for a national format.

ParameterTypeDescription
$readerFormatReader
Returns
self

The open core packages are MIT licensed. The legal wording of the country packs must be confirmed by a tax adviser.