AddFacturXAssociatedFileFromString

Document properties

Description

Writes e-invoice XML as a PDF/A-3 associated file and generates the required XMP e-invoice metadata for Factur-X, ZUGFeRD, and XRechnung profiles

Syntax

Delphi

Function TPDFlib.AddFacturXAssociatedFileFromString(Const XMLBytes: AnsiString; Const ConformanceLevel, FileName, Description, Relationship, Version, CountryCode: WideString): Integer;

Parameters

XMLBytesThe raw UTF-8 XML bytes to embed
ConformanceLevelThe invoice profile level, such as MINIMUM, BASIC WL, BASIC, EN16931, EXTENDED, XRECHNUNG, EXTENDED-CTC-FR, or EXTENDED-B2B-FR
FileNameThe embedded XML file name, usually factur-x.xml, xrechnung.xml, zugferd-invoice.xml, or ZUGFeRD-invoice.xml; an empty value defaults to factur-x.xml
DescriptionThe optional /Desc text written to the file specification
RelationshipThe /AFRelationship value; an empty value defaults to Alternative
VersionThe invoice profile version; an empty value defaults to 1.0
CountryCodeAn optional country profile code, such as an empty string, DE, or FR

Return values

0The document is not in a PDF/A-3 mode, the XML or profile combination is invalid, or invoice XML has already been added
Non-zeroThe object handle of the newly created file specification

Remarks

The method validates the file name, conformance level, version, country profile, and /AFRelationship before writing the attachment

COMFORT is accepted only with ZUGFeRD-invoice.xml and version 1.0; zugferd-invoice.xml selects the ZUGFeRD 2.0 profile, and xrechnung.xml selects the XRECHNUNG profile

The method writes DocumentFileName, DocumentType, Version, and ConformanceLevel XMP fields and checks that the XML guideline ID matches the selected profile. The normal visible invoice page content is still created by the caller before saving

Example

// Add EN 16931 invoice XML to a PDF/A-3b document
var
  FileID: Integer;
begin
  PDF.SetPDFAMode(5);
  PDF.NewDocument;
  FileID := PDF.AddFacturXAssociatedFileFromString(
    InvoiceXML,
    'EN16931',
    'factur-x.xml',
    'Factur-X invoice XML',
    'Alternative',
    '1.0',
    '');
  if FileID = 0 then Exit;
  PDF.SaveToFile('factur-x.pdf');
end;

See also

AddPDFA3AssociatedFileFromString, DetectFacturXInvoice, ValidateFacturXInvoice, ExtractFacturXXMLToString