From d0f49749e0803bb785e6abcb3101fedd6ca0536b Mon Sep 17 00:00:00 2001 From: jstaerk Date: Wed, 21 Aug 2024 06:50:36 +0200 Subject: [PATCH] closees #452 --- History.md | 6 +- .../ZUGFeRD/ZUGFeRDExporterFromA3.java | 98 +++++++++---------- 2 files changed, 51 insertions(+), 53 deletions(-) diff --git a/History.md b/History.md index 36878c7e..f4f94f14 100644 --- a/History.md +++ b/History.md @@ -1,5 +1,6 @@ - #420 - #441 +- #431 support reasoncodes - Enhance Charges/Allowances with reasonCode. #432 - Fix build warnings from editing and building. #415 - ZUGFeRDVisualizer.toPDF(): generate PDF/A-3b. #400 @@ -7,8 +8,9 @@ and XML (zii.getFileAttachmentsXML) - #436 and #370. (langfr) - refactor(ZUGFeRDVisualizer): improve PDF visualization performance #438 - - +- trying to default product on empty description +- #452 +- 2.12.0 ======= 2024-07-20 diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporterFromA3.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporterFromA3.java index 0dd548e5..dea69a6f 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporterFromA3.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporterFromA3.java @@ -85,6 +85,7 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte this.ignorePDFAErrors = true; return this; } + protected PDFAConformanceLevel conformanceLevel = PDFAConformanceLevel.UNICODE; protected ArrayList fileAttachments = new ArrayList<>(); @@ -223,17 +224,16 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte * @return the filename of the file to be embedded */ public String getFilenameForVersion(int ver, Profile profile) { + if (profile.getName().equals("XRECHNUNG")) { + return "xrechnung.xml"; + } if (isFacturX) { return "factur-x.xml"; } else { if (ver == 1) { return "ZUGFeRD-invoice.xml"; } else { - if (profile.getName().equals("XRECHNUNG")) { - return "xrechnung.xml"; - } else { - return "zugferd-invoice.xml"; - } + return "zugferd-invoice.xml"; } } } @@ -247,7 +247,7 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte * @deprecated It's now the default anyway */ @Deprecated - public ZUGFeRDExporterFromA3 setFacturX() { + public ZUGFeRDExporterFromA3 setFacturX() { isFacturX = true; return this; } @@ -260,10 +260,9 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte * * @param XRechnungVersion the XRechnung version */ - public void setXRechnungSpecificVersion(String XRechnungVersion) - { - this.XRechnungVersion = XRechnungVersion; - } + public void setXRechnungSpecificVersion(String XRechnungVersion) { + this.XRechnungVersion = XRechnungVersion; + } /*** @@ -308,13 +307,13 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte * @throws IOException if anything is wrong in the target location */ @Override - public void export(String ZUGFeRDfilename) throws IOException { + public void export(String ZUGFeRDfilename) throws IOException { if (!documentPrepared) { prepareDocument(); } if ((!fileAttached) && (attachZUGFeRDHeaders)) { throw new IOException( - "File must be attached (usually with setTransaction) before perfoming this operation"); + "File must be attached (usually with setTransaction) before perfoming this operation"); } doc.save(ZUGFeRDfilename, CompressParameters.NO_COMPRESSION); if (!disableAutoClose) { @@ -336,13 +335,13 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte * @throws IOException if anything is wrong in the OutputStream */ @Override - public void export(OutputStream output) throws IOException { + public void export(OutputStream output) throws IOException { if (!documentPrepared) { prepareDocument(); } if ((!fileAttached) && (attachZUGFeRDHeaders)) { throw new IOException( - "File must be attached (usually with setTransaction) before perfoming this operation"); + "File must be attached (usually with setTransaction) before perfoming this operation"); } doc.save(output, CompressParameters.NO_COMPRESSION); if (!disableAutoClose) { @@ -440,7 +439,7 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte cosArray.add(fs); doc.getDocumentCatalog().getCOSObject().setItem("AF", cosArray); } else if ((AFEntry instanceof COSObject) && - ((COSObject) AFEntry).getObject() instanceof COSArray) { + ((COSObject) AFEntry).getObject() instanceof COSArray) { COSArray cosArray = (COSArray) ((COSObject) AFEntry).getObject(); cosArray.add(fs); } else { @@ -534,19 +533,18 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte */ protected void addXMP(XMPMetadata metadata) { - String metaDataVersion = null; // default will be used + String metaDataVersion = null; // default will be used - // The XRechnung version may be settable from outside. - if ((this.XRechnungVersion != null) && (this.profile != null) && - this.profile.getName().equalsIgnoreCase(Profiles.getByName("XRECHNUNG").getName())) - { - metaDataVersion = this.XRechnungVersion; - } + // The XRechnung version may be settable from outside. + if ((this.XRechnungVersion != null) && (this.profile != null) && + this.profile.getName().equalsIgnoreCase(Profiles.getByName("XRECHNUNG").getName())) { + metaDataVersion = this.XRechnungVersion; + } if (attachZUGFeRDHeaders) { XMPSchemaZugferd zf = new XMPSchemaZugferd(metadata, ZFVersion, isFacturX, xmlProvider.getProfile(), - getNamespaceForVersion(ZFVersion), getPrefixForVersion(ZFVersion), - getFilenameForVersion(ZFVersion, xmlProvider.getProfile()), metaDataVersion); + getNamespaceForVersion(ZFVersion), getPrefixForVersion(ZFVersion), + getFilenameForVersion(ZFVersion, xmlProvider.getProfile()), metaDataVersion); metadata.addSchema(zf); } @@ -557,8 +555,7 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte } private void removeCidSet(PDDocument doc) - throws IOException - { + throws IOException { // https://github.com/ZUGFeRD/mustangproject/issues/249 COSName cidSet = COSName.getPDFName("CIDSet"); @@ -577,8 +574,8 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte PDType0Font typedFont = (PDType0Font) pdFont; if (typedFont.getDescendantFont() instanceof PDCIDFontType2) { - @SuppressWarnings ("unused") - PDCIDFontType2 f = (PDCIDFontType2) typedFont.getDescendantFont(); + @SuppressWarnings("unused") + PDCIDFontType2 f = (PDCIDFontType2) typedFont.getDescendantFont(); PDFontDescriptor fontDescriptor = pdFont.getFontDescriptor(); fontDescriptor.getCOSObject().removeItem(cidSet); @@ -637,7 +634,7 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte * @throws IOException if anything is wrong with already loaded PDF */ @Override - public IExporter setTransaction(IExportableTransaction trans) throws IOException { + public IExporter setTransaction(IExportableTransaction trans) throws IOException { this.trans = trans; return prepare(); } @@ -647,22 +644,20 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte xmlProvider.generateXML(trans); String filename = getFilenameForVersion(ZFVersion, xmlProvider.getProfile()); - String relationship = "Alternative"; - // ZUGFeRD 2.1.1 Technical Supplement | Part A | 2.2.2. Data Relationship - // See documentation ZUGFeRD211_EN/Documentation/ZUGFeRD-2.1.1 - Specification_TA_Part-A.pdf - // https://www.ferd-net.de/standards/zugferd-2.1.1/index.html - if ((this.profile != null) && (ZFVersion >= 2)) - { - if (this.profile.getName().equalsIgnoreCase(Profiles.getByName("MINIMUM").getName()) || - this.profile.getName().equalsIgnoreCase(Profiles.getByName("BASICWL").getName())) - { - relationship = "Data"; - } - } + String relationship = "Alternative"; + // ZUGFeRD 2.1.1 Technical Supplement | Part A | 2.2.2. Data Relationship + // See documentation ZUGFeRD211_EN/Documentation/ZUGFeRD-2.1.1 - Specification_TA_Part-A.pdf + // https://www.ferd-net.de/standards/zugferd-2.1.1/index.html + if ((this.profile != null) && (ZFVersion >= 2)) { + if (this.profile.getName().equalsIgnoreCase(Profiles.getByName("MINIMUM").getName()) || + this.profile.getName().equalsIgnoreCase(Profiles.getByName("BASICWL").getName())) { + relationship = "Data"; + } + } PDFAttachGenericFile(doc, filename, relationship, - "Invoice metadata conforming to ZUGFeRD standard (http://www.ferd-net.de/front_content.php?idcat=231&lang=4)", - "text/xml", xmlProvider.getXML()); + "Invoice metadata conforming to ZUGFeRD standard (http://www.ferd-net.de/front_content.php?idcat=231&lang=4)", + "text/xml", xmlProvider.getXML()); for (FileAttachment attachment : fileAttachments) { PDFAttachGenericFile(doc, attachment.getFilename(), attachment.getRelation(), attachment.getDescription(), attachment.getMimetype(), attachment.getData()); @@ -674,12 +669,12 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte /** * Reads the XMPMetadata from the PDDocument, if it exists. * Otherwise creates XMPMetadata. + * * @return the finished XMPMetadata object * @throws IOException when e.g. XmpParsingException */ protected XMPMetadata getXmpMetadata() - throws IOException - { + throws IOException { PDMetadata meta = doc.getDocumentCatalog().getMetadata(); if ((meta != null) && (meta.getLength() > 0)) { try { @@ -701,6 +696,7 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte /** * Sets the producer if the overwrite flag is set or the producer is not already set. * Sets the PDFVersion to 1.4 if the field is empty. + * * @param xmp the metadata as XML */ protected void writeAdobePDFSchema(XMPMetadata xmp) { @@ -823,11 +819,11 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte /** * Adds an OutputIntent and the sRGB color profile if no OutputIntent exist + * * @throws IOException if the ICC file cannot be read or attached to doc */ protected void addSRGBOutputIntend() - throws IOException - { + throws IOException { if (!doc.getDocumentCatalog().getOutputIntents().isEmpty()) { return; } @@ -892,12 +888,12 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte public ZUGFeRDExporterFromA3 setZUGFeRDVersion(EStandard est, int version) { this.ZFVersion = version; - if ((version<1) || (version>2)) { + if ((version < 1) || (version > 2)) { throw new IllegalArgumentException("Version not supported"); } - int generation=version; - if ((est==EStandard.facturx)&&(version==1)) { - generation=2; + int generation = version; + if ((est == EStandard.facturx) && (version == 1)) { + generation = 2; } if (generation == 1) { ZUGFeRD1PullProvider z1p = new ZUGFeRD1PullProvider();