ZUGFeRD additional attachments

69 views
Skip to first unread message

Roman

unread,
Jul 14, 2021, 8:54:16 AM7/14/21
to ZUGFeRD
Hi!

I need to add some pdf files as additional attachments into the ZUGFeRD (1.0) pdf not only the xml invoice file. Currently there seems to be no way to do this with Mustang right?

Any chance that will be possible in the near future?

Kind Regards
Roman

Roman

unread,
Jul 14, 2021, 9:53:10 AM7/14/21
to ZUGFeRD
I also tried using other libraries just to add the attachments either before or after adding the xml via Mustang. But nothing worked.

Once it is pdf/a3 with invoice attached the other libraries wont touch it. (unsupported format, no pdf header found, nullpointer Ex... etc)

And if i add the attachments to a pdfa/1 file before adding the invoice, Mustang wont touch it (not a valid PDF/A file...)

kind regards
Roman

jochen...@gmail.com

unread,
Aug 5, 2021, 7:15:15 AM8/5/21
to ZUGFeRD
Hi,
sorry this somehow slipped my attention. 
You can add attachments, both BASE64-encoded in the XML 
FileAttachment fe1=new FileAttachment("one.pdf", "application/pdf", "Alternative", b);
FileAttachment fe2=new FileAttachment("two.pdf", "application/pdf", "Alternative", b);
Invoice i = new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date())
.setSender(new TradeParty(orgname,"teststr","55232","teststadt","DE").addTaxID("DE4711").addVATID("DE0815").setContact(new Contact("Hans Test","+49123456789","te...@example.org")).addBankDetails(new BankDetails("DE12500105170648489890","COBADEFXXX")))
.setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE"))
.setReferenceNumber("991-01484-64")//leitweg-id
// not using any VAT, this is also a test of zero-rated goods:
.setNumber(number).addItem(new Item(new Product("Testprodukt", "", "C62", BigDecimal.ZERO), amount, new BigDecimal(1.0)))
.embedFileInXML(fe1).embedFileInXML(fe2);

as well as as separate file attachments embedded in the PDF
ZUGFeRDExporterFromA1 ze = new ZUGFeRDExporterFromA1().setProducer("My Application")
.setCreator(System.getProperty("user.name")).setZUGFeRDVersion(2).ignorePDFAErrors()
.load("sourcefuile.pdf")) {
byte[] b = {12, 13};
ze.attachFile("one.pdf", b, "application/pdf", "Alternative");
ze.attachFile("two.pdf", b, "application/pdf", "Alternative");
ze.setTransaction(new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()).setSender(new TradeParty(orgname, "teststr", "55232", "teststadt", "DE").addTaxID(taxID)).setOwnVATID("DE0815").setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE").addVATID("DE4711").setContact(new Contact("Franz Müller", "01779999999", "fr...@mueller.de", "teststr. 12", "55232", "Entenhausen", "DE"))).setNumber(number).addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), price, new BigDecimal(1.0)))

);
String theXML = new String(ze.getProvider().getXML());
assertTrue(theXML.contains("<rsm:CrossIndustryInvoice"));
ze.export("filename.pdf");

The source code of this post was hidden in the tests, I'll add it to the homepage.

apologies and kind regards
Jochen

Roman

unread,
Aug 20, 2021, 6:38:36 AM8/20/21
to ZUGFeRD
Hi,

thank you for your time and effort. I forgot to mention that i can't use the api directly, because the project allready uses a (rather old) pdfbox version that seems incompatible. Because when i try i get:

java.lang.NoSuchMethodError: org.apache.pdfbox.pdmodel.PDDocument.load([B)Lorg/apache/pdfbox/pdmodel/PDDocument;
at org.mustangproject.ZUGFeRD.ZUGFeRDExporterFromA3.load(ZUGFeRDExporterFromA3.java:236)

Updating the pdfbox isnt going to happen anytime soon because of the migration workload for which there simply is no time right now. So i'm stuck with the command line tool for the time being.

Just found the code for the command line tool and realized inserting attachments isn't in there yet. Any chance that is going to happen soon?

Else i guess i'll have to use above code example to add that to the command line interface myself :)

Kind regards
Roman
Reply all
Reply to author
Forward
0 new messages