diff --git a/History.md b/History.md index fba3aa1a..42272163 100644 --- a/History.md +++ b/History.md @@ -1,8 +1,12 @@ -1.5.6 +1.6.0 ===== +2019-02-03 -closes #69. +Closes #69. Corrected EN 16931 XMP Schema Extension header +Can now read xmp metadata via ZUGFeRDImporter getXMP +Exporting valid EN16931 Factur-X when version/profile set to 2/EN16931 mode + 1.5.5 ===== diff --git a/doc/MustangDev.en.odt b/doc/MustangDev.en.odt index 0a65fcea..b9b50a21 100644 Binary files a/doc/MustangDev.en.odt and b/doc/MustangDev.en.odt differ diff --git a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java b/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java index 07315afd..b71f4b1f 100644 --- a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java +++ b/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java @@ -33,17 +33,11 @@ import java.io.IOException; import java.io.InputStream; import java.util.List; import java.util.Map; -import java.util.logging.Level; import java.util.logging.Logger; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathConstants; -import javax.xml.xpath.XPathExpression; -import javax.xml.xpath.XPathFactory; - import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocumentNameDictionary; import org.apache.pdfbox.pdmodel.PDEmbeddedFilesNameTreeNode; @@ -79,6 +73,7 @@ public class ZUGFeRDImporter { private boolean amountFound; private boolean extractAttempt = false; private boolean parsed = false; + private String xmpString = null; // XMP metadata private static final Logger LOG = Logger.getLogger(ZUGFeRDImporter.class.getName()); /** @@ -98,6 +93,21 @@ public class ZUGFeRDImporter { ioe.printStackTrace(); } } + + static String convertStreamToString(java.io.InputStream is) { + // source https://stackoverflow.com/questions/309424/how-do-i-read-convert-an-inputstream-into-a-string-in-java referring to + // https://community.oracle.com/blogs/pat/2004/10/23/stupid-scanner-tricks + java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A"); + return s.hasNext() ? s.next() : ""; + } + + /*** + * get xmp metadata of the PDF, null if not available + * @return string + */ + public String getXMP() { + return xmpString; + } /** * Extracts a ZUGFeRD invoice from a PDF document represented by an input @@ -112,6 +122,10 @@ public class ZUGFeRDImporter { try (PDDocument doc = PDDocument.load(pdfStream)) { // PDDocumentInformation info = doc.getDocumentInformation(); PDDocumentNameDictionary names = new PDDocumentNameDictionary(doc.getDocumentCatalog()); + //start + InputStream XMP=doc.getDocumentCatalog().getMetadata().exportXMPMetadata(); + + xmpString=convertStreamToString(XMP); etn = names.getEmbeddedFiles(); if (etn == null) { return; @@ -134,6 +148,7 @@ public class ZUGFeRDImporter { } } + private void extractFiles(Map names) throws IOException { for (String filename : names.keySet()) { diff --git a/src/test/java/org/mustangproject/ZUGFeRD/MustangReaderWriterTest.java b/src/test/java/org/mustangproject/ZUGFeRD/MustangReaderWriterTest.java index 32bcfeb3..b7a63266 100644 --- a/src/test/java/org/mustangproject/ZUGFeRD/MustangReaderWriterTest.java +++ b/src/test/java/org/mustangproject/ZUGFeRD/MustangReaderWriterTest.java @@ -378,6 +378,81 @@ public class MustangReaderWriterTest extends TestCase implements IZUGFeRDExporta String amount = zi.getAmount(); + assertEquals("\n" + + " \n" + + " \n" + + " \n" + + " uuid:6776DD95-DAF6-768E-DAE6-2697750D95C5\n" + + " uuid:47380404-5938-FE2C-8F0B-B505DCE43BF5\n" + + " \n" + + " \n" + + " BASIC\n" + + " ZUGFeRD-invoice.xml\n" + + " INVOICE\n" + + " 1.0\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " ZUGFeRD PDFA Extension Schema\n" + + " urn:ferd:pdfa:CrossIndustryDocument:invoice:1p0#\n" + + " zf\n" + + " \n" + + " \n" + + " \n" + + " DocumentFileName\n" + + " Text\n" + + " external\n" + + " name of the embedded XML invoice file\n" + + " \n" + + " \n" + + " DocumentType\n" + + " Text\n" + + " external\n" + + " INVOICE\n" + + " \n" + + " \n" + + " Version\n" + + " Text\n" + + " external\n" + + " The actual version of the ZUGFeRD XML schema\n" + + " \n" + + " \n" + + " ConformanceLevel\n" + + " Text\n" + + " external\n" + + " The conformance level of the embedded ZUGFeRD data\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " 3\n" + + " B\n" + + " \n" + + " \n" + + " 2014-07-11T13:39:46+02:00\n" + + " 2014-07-11T13:39:46+02:00\n" + + " zugferd_invoice.java\n" + + " 2014-07-11T13:39:46+02:00\n" + + " \n" + + " \n" + + " PDFlib Personalization Server 9.0.3 (JDK 1.6/Mac OS X-10.6 64)\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " ZUGFeRD Rechnung $Revision: 1.13 $\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "", zi.getXMP()); // this resembles the data written in MustangReaderWriterCustomXMLTest assertEquals(amount, "1005.55");