This commit is contained in:
jstaerk
2024-08-21 06:50:36 +02:00
parent 23244cffa6
commit d0f49749e0
2 changed files with 51 additions and 53 deletions

View File

@@ -1,5 +1,6 @@
- #420 - #420
- #441 - #441
- #431 support reasoncodes
- Enhance Charges/Allowances with reasonCode. #432 - Enhance Charges/Allowances with reasonCode. #432
- Fix build warnings from editing and building. #415 - Fix build warnings from editing and building. #415
- ZUGFeRDVisualizer.toPDF(): generate PDF/A-3b. #400 - ZUGFeRDVisualizer.toPDF(): generate PDF/A-3b. #400
@@ -7,8 +8,9 @@
and XML (zii.getFileAttachmentsXML) and XML (zii.getFileAttachmentsXML)
- #436 and #370. (langfr) - #436 and #370. (langfr)
- refactor(ZUGFeRDVisualizer): improve PDF visualization performance #438 - refactor(ZUGFeRDVisualizer): improve PDF visualization performance #438
- trying to default product on empty description
- #452
-
2.12.0 2.12.0
======= =======
2024-07-20 2024-07-20

View File

@@ -85,6 +85,7 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
this.ignorePDFAErrors = true; this.ignorePDFAErrors = true;
return this; return this;
} }
protected PDFAConformanceLevel conformanceLevel = PDFAConformanceLevel.UNICODE; protected PDFAConformanceLevel conformanceLevel = PDFAConformanceLevel.UNICODE;
protected ArrayList<FileAttachment> fileAttachments = new ArrayList<>(); protected ArrayList<FileAttachment> fileAttachments = new ArrayList<>();
@@ -223,17 +224,16 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
* @return the filename of the file to be embedded * @return the filename of the file to be embedded
*/ */
public String getFilenameForVersion(int ver, Profile profile) { public String getFilenameForVersion(int ver, Profile profile) {
if (profile.getName().equals("XRECHNUNG")) {
return "xrechnung.xml";
}
if (isFacturX) { if (isFacturX) {
return "factur-x.xml"; return "factur-x.xml";
} else { } else {
if (ver == 1) { if (ver == 1) {
return "ZUGFeRD-invoice.xml"; return "ZUGFeRD-invoice.xml";
} else { } else {
if (profile.getName().equals("XRECHNUNG")) { return "zugferd-invoice.xml";
return "xrechnung.xml";
} else {
return "zugferd-invoice.xml";
}
} }
} }
} }
@@ -247,7 +247,7 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
* @deprecated It's now the default anyway * @deprecated It's now the default anyway
*/ */
@Deprecated @Deprecated
public ZUGFeRDExporterFromA3 setFacturX() { public ZUGFeRDExporterFromA3 setFacturX() {
isFacturX = true; isFacturX = true;
return this; return this;
} }
@@ -260,10 +260,9 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
* *
* @param XRechnungVersion the XRechnung version * @param XRechnungVersion the XRechnung version
*/ */
public void setXRechnungSpecificVersion(String XRechnungVersion) public void setXRechnungSpecificVersion(String XRechnungVersion) {
{ this.XRechnungVersion = 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 * @throws IOException if anything is wrong in the target location
*/ */
@Override @Override
public void export(String ZUGFeRDfilename) throws IOException { public void export(String ZUGFeRDfilename) throws IOException {
if (!documentPrepared) { if (!documentPrepared) {
prepareDocument(); prepareDocument();
} }
if ((!fileAttached) && (attachZUGFeRDHeaders)) { if ((!fileAttached) && (attachZUGFeRDHeaders)) {
throw new IOException( 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); doc.save(ZUGFeRDfilename, CompressParameters.NO_COMPRESSION);
if (!disableAutoClose) { if (!disableAutoClose) {
@@ -336,13 +335,13 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
* @throws IOException if anything is wrong in the OutputStream * @throws IOException if anything is wrong in the OutputStream
*/ */
@Override @Override
public void export(OutputStream output) throws IOException { public void export(OutputStream output) throws IOException {
if (!documentPrepared) { if (!documentPrepared) {
prepareDocument(); prepareDocument();
} }
if ((!fileAttached) && (attachZUGFeRDHeaders)) { if ((!fileAttached) && (attachZUGFeRDHeaders)) {
throw new IOException( 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); doc.save(output, CompressParameters.NO_COMPRESSION);
if (!disableAutoClose) { if (!disableAutoClose) {
@@ -440,7 +439,7 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
cosArray.add(fs); cosArray.add(fs);
doc.getDocumentCatalog().getCOSObject().setItem("AF", cosArray); doc.getDocumentCatalog().getCOSObject().setItem("AF", cosArray);
} else if ((AFEntry instanceof COSObject) && } else if ((AFEntry instanceof COSObject) &&
((COSObject) AFEntry).getObject() instanceof COSArray) { ((COSObject) AFEntry).getObject() instanceof COSArray) {
COSArray cosArray = (COSArray) ((COSObject) AFEntry).getObject(); COSArray cosArray = (COSArray) ((COSObject) AFEntry).getObject();
cosArray.add(fs); cosArray.add(fs);
} else { } else {
@@ -534,19 +533,18 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
*/ */
protected void addXMP(XMPMetadata metadata) { 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. // The XRechnung version may be settable from outside.
if ((this.XRechnungVersion != null) && (this.profile != null) && if ((this.XRechnungVersion != null) && (this.profile != null) &&
this.profile.getName().equalsIgnoreCase(Profiles.getByName("XRECHNUNG").getName())) this.profile.getName().equalsIgnoreCase(Profiles.getByName("XRECHNUNG").getName())) {
{ metaDataVersion = this.XRechnungVersion;
metaDataVersion = this.XRechnungVersion; }
}
if (attachZUGFeRDHeaders) { if (attachZUGFeRDHeaders) {
XMPSchemaZugferd zf = new XMPSchemaZugferd(metadata, ZFVersion, isFacturX, xmlProvider.getProfile(), XMPSchemaZugferd zf = new XMPSchemaZugferd(metadata, ZFVersion, isFacturX, xmlProvider.getProfile(),
getNamespaceForVersion(ZFVersion), getPrefixForVersion(ZFVersion), getNamespaceForVersion(ZFVersion), getPrefixForVersion(ZFVersion),
getFilenameForVersion(ZFVersion, xmlProvider.getProfile()), metaDataVersion); getFilenameForVersion(ZFVersion, xmlProvider.getProfile()), metaDataVersion);
metadata.addSchema(zf); metadata.addSchema(zf);
} }
@@ -557,8 +555,7 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
} }
private void removeCidSet(PDDocument doc) private void removeCidSet(PDDocument doc)
throws IOException throws IOException {
{
// https://github.com/ZUGFeRD/mustangproject/issues/249 // https://github.com/ZUGFeRD/mustangproject/issues/249
COSName cidSet = COSName.getPDFName("CIDSet"); COSName cidSet = COSName.getPDFName("CIDSet");
@@ -577,8 +574,8 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
PDType0Font typedFont = (PDType0Font) pdFont; PDType0Font typedFont = (PDType0Font) pdFont;
if (typedFont.getDescendantFont() instanceof PDCIDFontType2) { if (typedFont.getDescendantFont() instanceof PDCIDFontType2) {
@SuppressWarnings ("unused") @SuppressWarnings("unused")
PDCIDFontType2 f = (PDCIDFontType2) typedFont.getDescendantFont(); PDCIDFontType2 f = (PDCIDFontType2) typedFont.getDescendantFont();
PDFontDescriptor fontDescriptor = pdFont.getFontDescriptor(); PDFontDescriptor fontDescriptor = pdFont.getFontDescriptor();
fontDescriptor.getCOSObject().removeItem(cidSet); 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 * @throws IOException if anything is wrong with already loaded PDF
*/ */
@Override @Override
public IExporter setTransaction(IExportableTransaction trans) throws IOException { public IExporter setTransaction(IExportableTransaction trans) throws IOException {
this.trans = trans; this.trans = trans;
return prepare(); return prepare();
} }
@@ -647,22 +644,20 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
xmlProvider.generateXML(trans); xmlProvider.generateXML(trans);
String filename = getFilenameForVersion(ZFVersion, xmlProvider.getProfile()); String filename = getFilenameForVersion(ZFVersion, xmlProvider.getProfile());
String relationship = "Alternative"; String relationship = "Alternative";
// ZUGFeRD 2.1.1 Technical Supplement | Part A | 2.2.2. Data Relationship // 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 // 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 // https://www.ferd-net.de/standards/zugferd-2.1.1/index.html
if ((this.profile != null) && (ZFVersion >= 2)) if ((this.profile != null) && (ZFVersion >= 2)) {
{ if (this.profile.getName().equalsIgnoreCase(Profiles.getByName("MINIMUM").getName()) ||
if (this.profile.getName().equalsIgnoreCase(Profiles.getByName("MINIMUM").getName()) || this.profile.getName().equalsIgnoreCase(Profiles.getByName("BASICWL").getName())) {
this.profile.getName().equalsIgnoreCase(Profiles.getByName("BASICWL").getName())) relationship = "Data";
{ }
relationship = "Data"; }
}
}
PDFAttachGenericFile(doc, filename, relationship, PDFAttachGenericFile(doc, filename, relationship,
"Invoice metadata conforming to ZUGFeRD standard (http://www.ferd-net.de/front_content.php?idcat=231&lang=4)", "Invoice metadata conforming to ZUGFeRD standard (http://www.ferd-net.de/front_content.php?idcat=231&lang=4)",
"text/xml", xmlProvider.getXML()); "text/xml", xmlProvider.getXML());
for (FileAttachment attachment : fileAttachments) { for (FileAttachment attachment : fileAttachments) {
PDFAttachGenericFile(doc, attachment.getFilename(), attachment.getRelation(), attachment.getDescription(), attachment.getMimetype(), attachment.getData()); 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. * Reads the XMPMetadata from the PDDocument, if it exists.
* Otherwise creates XMPMetadata. * Otherwise creates XMPMetadata.
*
* @return the finished XMPMetadata object * @return the finished XMPMetadata object
* @throws IOException when e.g. XmpParsingException * @throws IOException when e.g. XmpParsingException
*/ */
protected XMPMetadata getXmpMetadata() protected XMPMetadata getXmpMetadata()
throws IOException throws IOException {
{
PDMetadata meta = doc.getDocumentCatalog().getMetadata(); PDMetadata meta = doc.getDocumentCatalog().getMetadata();
if ((meta != null) && (meta.getLength() > 0)) { if ((meta != null) && (meta.getLength() > 0)) {
try { 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 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. * Sets the PDFVersion to 1.4 if the field is empty.
*
* @param xmp the metadata as XML * @param xmp the metadata as XML
*/ */
protected void writeAdobePDFSchema(XMPMetadata xmp) { 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 * 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 * @throws IOException if the ICC file cannot be read or attached to doc
*/ */
protected void addSRGBOutputIntend() protected void addSRGBOutputIntend()
throws IOException throws IOException {
{
if (!doc.getDocumentCatalog().getOutputIntents().isEmpty()) { if (!doc.getDocumentCatalog().getOutputIntents().isEmpty()) {
return; return;
} }
@@ -892,12 +888,12 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
public ZUGFeRDExporterFromA3 setZUGFeRDVersion(EStandard est, int version) { public ZUGFeRDExporterFromA3 setZUGFeRDVersion(EStandard est, int version) {
this.ZFVersion = version; this.ZFVersion = version;
if ((version<1) || (version>2)) { if ((version < 1) || (version > 2)) {
throw new IllegalArgumentException("Version not supported"); throw new IllegalArgumentException("Version not supported");
} }
int generation=version; int generation = version;
if ((est==EStandard.facturx)&&(version==1)) { if ((est == EStandard.facturx) && (version == 1)) {
generation=2; generation = 2;
} }
if (generation == 1) { if (generation == 1) {
ZUGFeRD1PullProvider z1p = new ZUGFeRD1PullProvider(); ZUGFeRD1PullProvider z1p = new ZUGFeRD1PullProvider();