From 9f57cf8e8fa275158310f55cb9df23b205e5ec33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jochen=20Sta=CC=88rk?= Date: Mon, 8 Apr 2019 20:54:44 +0200 Subject: [PATCH] corrected PDF/A extension schema --- .../ZUGFeRD/ZUGFeRDExporter.java | 19 +++--- .../ZUGFeRD/MustangReaderWriterTest.java | 58 ++++++++++++++++++- 2 files changed, 66 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporter.java b/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporter.java index 925217ce..e5504667 100644 --- a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporter.java +++ b/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporter.java @@ -134,32 +134,31 @@ public class ZUGFeRDExporter implements Closeable { } public static String getNamespaceForVersion(int ver) { - if (ver == 1) { + if (isFacturX) { + return "urn:factur-x:pdfa:CrossIndustryDocument:invoice:1p0#"; + } else if (ver == 1) { return "urn:ferd:pdfa:CrossIndustryDocument:invoice:1p0#"; } else if (ver == 2) { - return "urn:factur-x:pdfa:CrossIndustryDocument:invoice:1p0#"; + return "urn:zugferd:pdfa:CrossIndustryDocument:invoice:2p0#"; + } else { throw new IllegalArgumentException("Version not supported"); } } public static String getPrefixForVersion(int ver) { - if (ver == 1) { - return "zf"; - } else if (ver == 2) { + if (isFacturX) { return "fx"; } else { - throw new IllegalArgumentException("Version not supported"); + return "zf"; } } public static String getFilenameForVersion(int ver) { - if (ver == 1) { - return "ZUGFeRD-invoice.xml"; - } else if ((ver == 2) || (isFacturX)) { + if (isFacturX) { return "factur-x.xml"; } else { - throw new IllegalArgumentException("Version not supported"); + return "ZUGFeRD-invoice.xml"; } } diff --git a/src/test/java/org/mustangproject/ZUGFeRD/MustangReaderWriterTest.java b/src/test/java/org/mustangproject/ZUGFeRD/MustangReaderWriterTest.java index 469ec565..f827bc06 100644 --- a/src/test/java/org/mustangproject/ZUGFeRD/MustangReaderWriterTest.java +++ b/src/test/java/org/mustangproject/ZUGFeRD/MustangReaderWriterTest.java @@ -510,6 +510,62 @@ public class MustangReaderWriterTest extends TestCase implements IZUGFeRDExporta ze.disableAutoClose(true); ze.export(TARGET_PDF); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ze.export(baos); + ze.close(); + String pdfContent = baos.toString("UTF-8"); + assertFalse(pdfContent.indexOf("(via mustangproject.org") == -1); + // check for pdf-a schema extension + assertFalse(pdfContent.indexOf("EN 16931") == -1); + assertFalse(pdfContent.indexOf("zf") == -1); + assertFalse(pdfContent.indexOf("urn:zugferd:pdfa:CrossIndustryDocument:invoice:2p0#") == -1); + + } + + // now check the contents (like MustangReaderTest) + ZUGFeRDImporter zi = new ZUGFeRDImporter(); + zi.extract(TARGET_PDF); + // Reading ZUGFeRD + + String amount = null; + String bic = null; + String iban = null; + String kto = null; + String holder = null; + String ref = null; + if (zi.canParse()) { + zi.parse(); + amount = zi.getAmount(); + bic = zi.getBIC(); + iban = zi.getIBAN(); + kto = zi.getKTO(); + holder = zi.getHolder(); + ref = zi.getForeignReference(); + } + + assertEquals(amount, "571.04"); + assertEquals(bic, getOwnBIC()); + assertEquals(iban, getOwnIBAN()); + assertEquals(kto, getOwnKto()); + assertEquals(holder, getOwnOrganisationName()); + assertEquals(ref, getNumber()); + + } + /* + public void testFXExport() throws Exception { + + final String TARGET_PDF = "./target/testout-MustangGnuaccountingBeispielRE-20171118_506fx.pdf"; + + // the writing part + try (InputStream SOURCE_PDF = this.getClass() + .getResourceAsStream("/MustangGnuaccountingBeispielRE-20171118_506blanko.pdf"); + + ZUGFeRDExporter ze = new ZUGFeRDExporterFromA1Factory().setZUGFeRDVersion(2).setZUGFeRDConformanceLevel(ZUGFeRDConformanceLevel.EN16931).load(SOURCE_PDF)) { + ze.setFacturX(); + ze.PDFattachZugferdFile(this); + ze.disableAutoClose(true); + ze.export(TARGET_PDF); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); ze.export(baos); ze.close(); @@ -550,7 +606,7 @@ public class MustangReaderWriterTest extends TestCase implements IZUGFeRDExporta assertEquals(ref, getNumber()); } - +*/ /** * @throws Exception * @Test(expected = IndexOutOfBoundsException.class)