Skip to main content

Module pdf

Module pdf 

Source
Expand description

Factur-X, ZUGFeRD and Order-X PDF files (feature pdf, on by default): the invoice XML a PDF/A-3 file embeds, extracted with einvoice_pdf, to be validated as any other document.

extract returns the embedded file named as the specifications require (INVOICE_FILE_NAMES), byte for byte, with its file specification (/AFRelationship, …) and the XMP metadata of the document (the PDF/A identification, the Factur-X / ZUGFeRD properties). Syntax::detect then tells which built-in rule set the XML is for:

fn validate(file: &[u8]) -> Result<einvoice_validator::Report, einvoice_validator::Error> {
    use einvoice_validator::{Syntax, Validator, pdf};

    let xml = if pdf::is_pdf(file) {
        let embedded = pdf::extract(file)?;
        println!("{} ({:?})", embedded.xml.file_name, embedded.xml.relationship);
        embedded.xml.data
    } else {
        file.to_vec()
    };
    let rule_set = Syntax::detect(&xml).map_or("cen-ubl", Syntax::builtin_rule_set);
    Validator::builtin(rule_set)?.validate_owned(xml)
}

Only the part of PDF on the path to the embedded files is read (see einvoice_pdf); anything else met there is refused rather than read approximately. The errors are Error::Pdf.

Structs§

Attachment
An embedded file: its file specification and its decoded content.
Embedded
What extract returns.
InvoiceMetadata
The Factur-X / ZUGFeRD / Order-X extension schema properties of the XMP metadata.
Limits
Bounds on the work done for one file, against hostile input. Every bound that is reached is an Error::LimitExceeded naming the field.
Metadata
The XMP metadata of the document catalog (/Metadata).

Enums§

AfRelationship
The relationship of an associated file to the document (/AFRelationship, ISO 32000-2, 14.13.2, Table 43).

Constants§

INVOICE_FILE_NAMES
The names under which the specifications embed the invoice XML: Factur-X (and ZUGFeRD 2.1 and later), ZUGFeRD 2.0, ZUGFeRD 1.0, XRechnung in ZUGFeRD, Order-X.

Functions§

extract
The embedded invoice XML of a Factur-X, ZUGFeRD or Order-X PDF, with its file specification and the document’s XMP metadata, with the default Limits.
extract_with
extract with explicit Limits.
is_pdf
Whether bytes start as a PDF file does (%PDF-), which no XML document does.