A ZUGFeRD invoice data is saved in xml format within a PDF document as a file attachment so that it can be programmatically parsed and processed. Qoppa’s PDF library jPDFProcess allows to extract the xml file.

Here is some sample code to extract the ZUGFeRD xml file contained in a PDF and save it to a file:

PDFDocument pdfDocument = new PDFDocument("c:\\qoppa\\testData\\zugferd_invoice.pdf", null);
Vector<IEmbeddedFile> embeddedFiles = pdfDocument.getEmbeddedFiles();
for (IEmbeddedFile ef : embeddedFiles)
{
  if ("ZUGFeRD-invoice.xml".equals(ef.getFileName()))
  {
   ef.saveFile(new File("c:\\qoppa\\testData\\ZUGFeRD-invoice.xml"));
   break;
  }
}
Tagged: