updated reading of invoice attachments
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
- #420
|
||||
- #441
|
||||
- Enhance Charges/Allowances with reasonCode. #432
|
||||
- Fix build warnings from editing and building. #415
|
||||
- ZUGFeRDVisualizer.toPDF(): generate PDF/A-3b. #400
|
||||
- allow access to invoice attachments via ZUGFeRDInvoiceImporter zii.getEmbeddedFilenames()/zii.getEmbeddedFile(filename)
|
||||
and XML (zii.getFileAttachments)
|
||||
- allow access to invoice attachments via ZUGFeRDInvoiceImporter zii.getFileAttachmentsPDF()
|
||||
and XML (zii.getFileAttachmentsXML)
|
||||
- #436 and #370. (langfr)
|
||||
- refactor(ZUGFeRDVisualizer): improve PDF visualization performance #438
|
||||
|
||||
|
||||
2.12.0
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
To check if the necessary tools are there, the build is in a stable state and works on your platform, e.g. download and extract https://github.com/ZUGFeRD/mustangproject/archive/master.zip and run ./mvnw clean package
|
||||
|
||||
Mvnw is a maven wrapper which will download maven.Maven is the dependency management tool which will download all libraries, their dependencies, and build the whole thing.
|
||||
Mvnw is a maven wrapper which will download maven.Maven is the dependency management tool which will download all libraries, their dependencies, and build the whole thing.
|
||||
|
||||
You will need a Java JDK, e.g. https://www.azul.com/downloads/zulu-community/?architecture=x86-64-bit&package=jdk
|
||||
@@ -60,7 +59,7 @@ to validate the XML part of the invoices.
|
||||
|
||||
## New build
|
||||
|
||||
Target platform is java 1.8
|
||||
Target platform is java 1.11
|
||||
|
||||
## Build
|
||||
|
||||
@@ -158,7 +157,7 @@ Sign in in GitHub and click on the profile picture -> Settings. Now just generat
|
||||

|
||||
The Token-ID is the password.
|
||||
|
||||
In .m2 also need a toolchains.xml which defines a Sun JDK 1.8 target like the following:
|
||||
In .m2 also need a toolchains.xml which defines a JDK 1.11 target like the following:
|
||||
```xml
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<toolchains>
|
||||
@@ -185,11 +184,11 @@ maybe not yet even existing new release version:
|
||||
|
||||
```
|
||||
cd validator/target
|
||||
mvn install:install-file -Dfile=validator-2.5.5-SNAPSHOT-shaded.jar -DgroupId=org.mustangproject -DartifactId=validator -Dversion=2.5.5 -Dpackaging=jar -DgeneratePom=true
|
||||
mvn install:install-file -Dfile=validator-2.12.0-SNAPSHOT-shaded.jar -Dclassifier=shaded -DgroupId=org.mustangproject -DartifactId=validator -Dversion=2.12.0 -Dpackaging=jar -DgeneratePom=true
|
||||
```
|
||||
In gradle you can use something like
|
||||
```
|
||||
implementation files('libs/validator-2.5.6-shaded.jar')
|
||||
implementation files('libs/validator-2.12.0-shaded.jar')
|
||||
```
|
||||
|
||||
|
||||
|
||||
@@ -40,10 +40,7 @@ import org.apache.pdfbox.pdmodel.PDEmbeddedFilesNameTreeNode;
|
||||
import org.apache.pdfbox.pdmodel.common.PDNameTreeNode;
|
||||
import org.apache.pdfbox.pdmodel.common.filespecification.PDComplexFileSpecification;
|
||||
import org.apache.pdfbox.pdmodel.common.filespecification.PDEmbeddedFile;
|
||||
import org.mustangproject.EStandard;
|
||||
import org.mustangproject.Item;
|
||||
import org.mustangproject.Product;
|
||||
import org.mustangproject.XMLTools;
|
||||
import org.mustangproject.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.w3c.dom.Document;
|
||||
@@ -65,7 +62,7 @@ public class ZUGFeRDImporter {
|
||||
/**
|
||||
* map filenames of all embedded files in the respective PDF
|
||||
*/
|
||||
private final HashMap<String, byte[]> PDFAttachments = new HashMap<>();
|
||||
private final ArrayList<FileAttachment> PDFAttachments = new ArrayList<>();
|
||||
/**
|
||||
* Raw XML form of the extracted data - may be directly obtained.
|
||||
*/
|
||||
@@ -107,25 +104,13 @@ public class ZUGFeRDImporter {
|
||||
|
||||
/***
|
||||
* return the file names of all files embedded into the PDF
|
||||
* @see for XML embedded files please use ZUGFeRDInvoiceImporter.getFileAttachments
|
||||
* @return a Stringset
|
||||
* @see for XML embedded files please use ZUGFeRDInvoiceImporter.getFileAttachmentsXML
|
||||
* @return a ArrayList of FileAttachments, empty if none
|
||||
*/
|
||||
public Set<String> getEmbeddedFilenames() {
|
||||
return PDFAttachments.keySet();
|
||||
public List<FileAttachment> getFileAttachmentsPDF() {
|
||||
return PDFAttachments;
|
||||
}
|
||||
|
||||
/***
|
||||
* returns the file contents of the specified filename embedded into the PDF
|
||||
* @param filename String
|
||||
* @return a bytearray, or null if the filename has not been fond
|
||||
*/
|
||||
public byte[] getEmbeddedFile(String filename) {
|
||||
|
||||
if (PDFAttachments.containsKey(filename)) {
|
||||
return PDFAttachments.get(filename);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -196,6 +181,7 @@ public class ZUGFeRDImporter {
|
||||
/**
|
||||
* filenames for invoice data (ZUGFeRD v1 and v2, Factur-X)
|
||||
*/
|
||||
|
||||
final PDEmbeddedFile embeddedFile = fileSpec.getEmbeddedFile();
|
||||
if ((filename.equals("ZUGFeRD-invoice.xml") || (filename.equals("zugferd-invoice.xml")) || filename.equals("factur-x.xml")) || filename.equals("xrechnung.xml") || filename.equals("order-x.xml") || filename.equals("cida.xml")) {
|
||||
containsMeta = true;
|
||||
@@ -215,7 +201,7 @@ public class ZUGFeRDImporter {
|
||||
if (filename.startsWith("additional_data")) {
|
||||
additionalXMLs.put(filename, embeddedFile.toByteArray());
|
||||
}
|
||||
PDFAttachments.put(filename, embeddedFile.toByteArray());
|
||||
PDFAttachments.add(new FileAttachment(filename, embeddedFile.getSubtype(), "Data", embeddedFile.toByteArray()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -345,7 +345,7 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
|
||||
xpr = xpath.compile("//*[local-name()=\"AttachmentBinaryObject\"]|//*[local-name()=\"EmbeddedDocumentBinaryObject\"]");
|
||||
NodeList attachmentNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET);
|
||||
for (int i = 0; i < attachmentNodes.getLength(); i++) {
|
||||
FileAttachment fa=new FileAttachment(attachmentNodes.item(i).getAttributes().getNamedItem("filename").getNodeValue(),attachmentNodes.item(i).getAttributes().getNamedItem("mimeCode").getNodeValue(),"",Base64.getDecoder().decode(attachmentNodes.item(i).getTextContent()));
|
||||
FileAttachment fa=new FileAttachment(attachmentNodes.item(i).getAttributes().getNamedItem("filename").getNodeValue(),attachmentNodes.item(i).getAttributes().getNamedItem("mimeCode").getNodeValue(),"Data", Base64.getDecoder().decode(attachmentNodes.item(i).getTextContent()));
|
||||
fileAttachments.add(fa);
|
||||
// filename = "Aufmass.png" mimeCode = "image/png"
|
||||
//EmbeddedDocumentBinaryObject cbc:EmbeddedDocumentBinaryObject mimeCode="image/png" filename="Aufmass.png"
|
||||
@@ -449,10 +449,10 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
|
||||
|
||||
/***
|
||||
*
|
||||
* @return the file attachments embedded in XML using base64,
|
||||
* @see for PDF embedded files use getEmbeddedFilenames()/getEmbeddedFile()
|
||||
* @return the file attachments embedded in XML (using base64) decoded as byte array,
|
||||
* @see for PDF embedded files in FX use getFileAttachmentsPDF()
|
||||
*/
|
||||
public List<FileAttachment> getFileAttachments() {
|
||||
public List<FileAttachment> getFileAttachmentsXML() {
|
||||
return fileAttachments;
|
||||
}
|
||||
|
||||
|
||||
@@ -133,7 +133,7 @@ public class XRTest extends TestCase {
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
List<FileAttachment> attachedFiles=zii.getFileAttachments();
|
||||
List<FileAttachment> attachedFiles=zii.getFileAttachmentsXML();
|
||||
assertNotNull(attachedFiles);
|
||||
assertEquals(attachedFiles.size(), 1);
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
*/
|
||||
package org.mustangproject.ZUGFeRD;
|
||||
|
||||
import org.mustangproject.FileAttachment;
|
||||
import org.mustangproject.Invoice;
|
||||
|
||||
import javax.xml.xpath.XPathExpressionException;
|
||||
@@ -296,15 +297,12 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase {
|
||||
byte[] fileB=null;
|
||||
|
||||
ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter("./target/testout-ZF2PushAttachments.pdf");
|
||||
for (String filename:zii.getEmbeddedFilenames()
|
||||
) {
|
||||
if (filename.equals("one.pdf")) {
|
||||
fileA=zii.getEmbeddedFile(filename);
|
||||
} else if (filename.equals("two.pdf")) {
|
||||
fileB=zii.getEmbeddedFile(filename);
|
||||
|
||||
for (FileAttachment fa:zii.getFileAttachmentsPDF()) {
|
||||
if (fa.getFilename().equals("one.pdf")) {
|
||||
fileA=fa.getData();
|
||||
} else if (fa.getFilename().equals("two.pdf")) {
|
||||
fileB=fa.getData();
|
||||
}
|
||||
|
||||
}
|
||||
byte[] b = {12, 13}; // the sample data that was used to write the files
|
||||
|
||||
|
||||
Reference in New Issue
Block a user