To create a ZUGFeRD PDF, you must start with an existing PDF/A file. The process involves:
- Initializing a
ZUGFeRDExporterFromPDFA and loading your source PDF. - Constructing an
Invoice object with details like TradeParty (sender/recipient), BankDetails, TaxID, and line Items. - Setting the invoice as the transaction in the exporter.
- Calling
export("filename.pdf") to generate the new file.
It is recommended to use BigDecimal for all monetary values to avoid rounding errors.
// 1. Setup Exporter
IZUGFeRDExporter ze = new ZUGFeRDExporterFromPDFA()
.load(sourcePDF)
.setProducer("My Application")
.setCreator(System.getProperty("user.name"));
// 2. Build Invoice
Invoice i = new Invoice()
.setDueDate(new Date())
.setIssueDate(new Date())
.setDeliveryDate(new Date())
.setSender(new TradeParty("ACME co", "teststr", "55232", "teststadt", "DE")
.addBankDetails(new BankDetails("777666555", "DE4321")))
.setOwnTaxID("4711")
.setOwnVATID("DE19990815")
.setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE")
.setContact(new Contact("nameRep", "phoneRep", "emailRep@test.com")))
.setNumber("X12")
.addItem(new Item(new Product("Testproduct", "", "H87", new BigDecimal(19)),
new BigDecimal(2.5), new BigDecimal(1.0)));
// 3. Export
ze.setTransaction(i);
ze.export("factur-x.pdf");