Upgrade of PDFBox to 2.0.5, Version upgrade to 1.4.0.0, add reference document to exporter interface (e.g. used for invoice corrections)

This commit is contained in:
Alexander Schmidt
2017-04-21 15:53:38 +02:00
26 changed files with 1661 additions and 1192 deletions

Binary file not shown.

View File

@@ -167,7 +167,7 @@ public class MustangWriter implements IZUGFeRDExportableTransaction {
@Override @Override
public String getOwnBIC() { public String getOwnBIC() {
return "COBADEFXXX"; return "COBADEFFXXX";
} }
@Override @Override

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -3,24 +3,66 @@
<parent> <parent>
<groupId>com.github.rayman2200</groupId> <groupId>com.github.rayman2200</groupId>
<artifactId>mustang-sample-project</artifactId> <artifactId>mustang-sample-project</artifactId>
<version>1.3.0-SNAPSHOT</version> <version>1.3.0.1-SNAPSHOT</version>
</parent> </parent>
<groupId>org.mustangproject.ZUGFeRD</groupId> <groupId>org.mustangproject.ZUGFeRD</groupId>
<artifactId>mustang</artifactId> <artifactId>mustang</artifactId>
<version>1.3.0-SNAPSHOT</version> <version>1.3.0.1-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>Mustang</name> <name>Mustang</name>
<description>The Mustang project is a java library to read and write ZUGFeRD meta data inside your invoice PDFs</description> <description>The Mustang project is a java library to read and write ZUGFeRD meta data inside your invoice PDFs</description>
<url>http://www.mustangproject.org/</url> <url>http://www.mustangproject.org/</url>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<minimizeJar>true</minimizeJar>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<excludes>
<!--exclude>classworlds:classworlds</exclude>
<exclude>junit:junit</exclude>
<exclude>jmock:*</exclude>
<exclude>*:xml-apis</exclude>
<exclude>org.apache.maven:lib:tests</exclude>
<exclude>log4j:log4j:jar:</exclude-->
</excludes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.glassfish.jaxb</groupId> <groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId> <artifactId>jaxb-runtime</artifactId>
<version>2.2.11</version> <version>2.2.11</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>preflight</artifactId>
<version>1.8.8</version>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>1.8.8</version>
</dependency>
</dependencies> </dependencies>
<mailingLists> <mailingLists>
@@ -56,5 +98,4 @@
</roles> </roles>
</developer> </developer>
</developers> </developers>
</project> </project>

View File

@@ -4,7 +4,7 @@ package org.mustangproject.ZUGFeRD;
* Neccessary interface for ZUGFeRD exporter * Neccessary interface for ZUGFeRD exporter
* Licensed under the APLv2 * Licensed under the APLv2
* @date 2014-05-10 * @date 2014-05-10
* @version 1.0 * @version 1.2.0
* @author jstaerk * @author jstaerk
* */ * */

View File

@@ -4,7 +4,7 @@ package org.mustangproject.ZUGFeRD;
* Neccessary interface for ZUGFeRD exporter * Neccessary interface for ZUGFeRD exporter
* Licensed under the APLv2 * Licensed under the APLv2
* @date 2014-05-10 * @date 2014-05-10
* @version 1.0 * @version 1.2.0
* @author jstaerk * @author jstaerk
* */ * */

View File

@@ -5,7 +5,7 @@ import java.math.BigDecimal;
* Necessary interface for ZUGFeRD exporter * Necessary interface for ZUGFeRD exporter
* Licensed under the APLv2 * Licensed under the APLv2
* @date 2014-05-10 * @date 2014-05-10
* @version 1.0 * @version 1.2.0
* @author jstaerk * @author jstaerk
* */ * */

View File

@@ -4,7 +4,7 @@ package org.mustangproject.ZUGFeRD;
* Neccessary interface for ZUGFeRD exporter * Neccessary interface for ZUGFeRD exporter
* Licensed under the APLv2 * Licensed under the APLv2
* @date 2014-05-10 to 2014-06-25 * @date 2014-05-10 to 2014-06-25
* @version 1.0.2 * @version 1.2.0
* @author jstaerk * @author jstaerk
* */ * */
@@ -127,7 +127,7 @@ public interface IZUGFeRDExportableTransaction {
* get main invoice currency used on the invoice * get main invoice currency used on the invoice
* @return * @return
*/ */
String getInvoiceCurrency(); String getCurrency();
/** /**
* get payment information text. e.g. Bank transfer * get payment information text. e.g. Bank transfer

View File

@@ -1,7 +1,14 @@
package org.mustangproject.ZUGFeRD; package org.mustangproject.ZUGFeRD;
import java.math.BigDecimal; import java.math.BigDecimal;
/**
* Mustangproject's ZUGFeRD implementation
* ZUGFeRD exporter helper class
* Licensed under the APLv2
* @date 2015-10-29
* @version 1.2.0
* @author jstaerk
* */
public class VATAmount { public class VATAmount {
public VATAmount(BigDecimal basis, BigDecimal calculated) { public VATAmount(BigDecimal basis, BigDecimal calculated) {

View File

@@ -4,7 +4,7 @@ package org.mustangproject.ZUGFeRD;
* ZUGFeRD exporter helper class * ZUGFeRD exporter helper class
* Licensed under the APLv2 * Licensed under the APLv2
* @date 2014-05-10 * @date 2014-05-10
* @version 1.0 * @version 1.2.0
* @author jstaerk * @author jstaerk
* */ * */
import org.apache.jempbox.impl.XMLUtil; import org.apache.jempbox.impl.XMLUtil;
@@ -112,6 +112,12 @@ import org.w3c.dom.Element;
Element propertyNode = schema.getOwnerDocument().createElement( Element propertyNode = schema.getOwnerDocument().createElement(
"pdfaSchema:property"); //$NON-NLS-1$ "pdfaSchema:property"); //$NON-NLS-1$
Element valueTypeNode = schema.getOwnerDocument().createElement(
"pdfaSchema:valueType"); //$NON-NLS-1$
Element seqListValueType = schema.getOwnerDocument().createElement(
"rdf:Seq"); //$NON-NLS-1$
Element sequenceNode = schema.getOwnerDocument().createElement( Element sequenceNode = schema.getOwnerDocument().createElement(
"rdf:Seq"); //$NON-NLS-1$ "rdf:Seq"); //$NON-NLS-1$
@@ -150,6 +156,9 @@ import org.w3c.dom.Element;
bagListNode.appendChild(propertyNode); bagListNode.appendChild(propertyNode);
valueTypeNode.appendChild(seqListValueType);
bagListNode.appendChild(valueTypeNode);
bagNode.appendChild(bagListNode); bagNode.appendChild(bagListNode);
schemasNode.appendChild(bagNode); schemasNode.appendChild(bagNode);

View File

@@ -4,7 +4,7 @@ package org.mustangproject.ZUGFeRD;
* ZUGFeRD exporter helper class * ZUGFeRD exporter helper class
* Licensed under the APLv2 * Licensed under the APLv2
* @date 2014-05-10 * @date 2014-05-10
* @version 1.0 * @version 1.2.0s
* @author jstaerk * @author jstaerk
* */ * */
import org.apache.jempbox.impl.XMLUtil; import org.apache.jempbox.impl.XMLUtil;
@@ -15,7 +15,7 @@ import org.w3c.dom.Element;
public class XMPSchemaZugferd extends XMPSchemaBasic public class XMPSchemaZugferd extends XMPSchemaBasic
{ {
private String conformanceLevel = "COMFORT"; private String conformanceLevel = "EXTENDED";
/** /**
* This is what needs to be added to the RDF metadata - basically the name of the embedded * This is what needs to be added to the RDF metadata - basically the name of the embedded

View File

@@ -15,6 +15,7 @@ import java.io.BufferedInputStream;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.util.Map; import java.util.Map;
import javax.management.RuntimeErrorException;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
@@ -34,12 +35,12 @@ import org.xml.sax.SAXException;
public class ZUGFeRDImporter { public class ZUGFeRDImporter {
/* /*
call extract(importFilename). call extract(importFilename).
containsMeta() will return if ZUGFeRD data has been found, containsMeta() will return if ZUGFeRD data has been found,
afterwards you can call getBIC(), getIBAN() etc. afterwards you can call getBIC(), getIBAN() etc.
*/ */
/**@var if metadata has been found */ /**@var if metadata has been found */
private boolean containsMeta=false; private boolean containsMeta=false;
/**@var the reference (i.e. invoice number) of the sender */ /**@var the reference (i.e. invoice number) of the sender */
@@ -48,16 +49,20 @@ public class ZUGFeRDImporter {
private String IBAN; private String IBAN;
private String holder; private String holder;
private String amount; private String amount;
private String dueDate;
/** Raw XML form of the extracted data - may be directly obtained. */ /** Raw XML form of the extracted data - may be directly obtained. */
private byte[] rawXML=null; private byte[] rawXML=null;
private String bankName; private String bankName;
private boolean amountFound; private boolean amountFound;
private boolean extracted=false;
private boolean parsed=false;
/** /**
* Extracts a ZUGFeRD invoice from a PDF document represented by a file name. * Extracts a ZUGFeRD invoice from a PDF document represented by a file name.
* Errors are just logged to STDOUT. * Errors are just logged to STDOUT.
*/ */
public void extract(String pdfFilename) public void extract(String pdfFilename)
{ {
try try
{ {
@@ -66,7 +71,7 @@ public class ZUGFeRDImporter {
{ {
ioe.printStackTrace(); ioe.printStackTrace();
} }
} }
/** /**
* Extracts a ZUGFeRD invoice from a PDF document represented by an input stream. * Extracts a ZUGFeRD invoice from a PDF document represented by an input stream.
@@ -106,6 +111,7 @@ public class ZUGFeRDImporter {
// FileOutputStream fos = new FileOutputStream(file); // FileOutputStream fos = new FileOutputStream(file);
rawXML = embeddedFile.getByteArray(); rawXML = embeddedFile.getByteArray();
setMeta(new String(rawXML)); setMeta(new String(rawXML));
extracted=true;
// fos.write(embeddedFile.getByteArray()); // fos.write(embeddedFile.getByteArray());
// fos.close(); // fos.close();
} }
@@ -123,12 +129,16 @@ public class ZUGFeRDImporter {
} }
} }
public void parse() { public void parse() {
DocumentBuilderFactory factory = null; DocumentBuilderFactory factory = null;
DocumentBuilder builder = null; DocumentBuilder builder = null;
Document document = null; Document document = null;
if (!extracted) {
throw new RuntimeException("extract() or extractLowLevel() must be used before parsing.");
}
factory = DocumentBuilderFactory.newInstance(); factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true); //otherwise we can not act namespace independend, i.e. use document.getElementsByTagNameNS("*",... factory.setNamespaceAware(true); //otherwise we can not act namespace independend, i.e. use document.getElementsByTagNameNS("*",...
try { try {
@@ -147,17 +157,17 @@ public class ZUGFeRDImporter {
ex2.printStackTrace(); ex2.printStackTrace();
} }
NodeList ndList ; NodeList ndList ;
// rootNode = document.getDocumentElement(); // rootNode = document.getDocumentElement();
// ApplicableSupplyChainTradeSettlement // ApplicableSupplyChainTradeSettlement
ndList = document.getDocumentElement() ndList = document.getDocumentElement()
.getElementsByTagNameNS("*","PaymentReference"); //$NON-NLS-1$ .getElementsByTagNameNS("*","PaymentReference"); //$NON-NLS-1$
for (int bookingIndex = 0; bookingIndex < ndList for (int bookingIndex = 0; bookingIndex < ndList
.getLength(); bookingIndex++) { .getLength(); bookingIndex++) {
Node booking = ndList.item(bookingIndex); Node booking = ndList.item(bookingIndex);
// if there is a attribute in the tag number:value // if there is a attribute in the tag number:value
setForeignReference(booking.getTextContent()); setForeignReference(booking.getTextContent());
} }
@@ -189,7 +199,7 @@ public class ZUGFeRDImporter {
<ram:BICID>DE5656565</ram:BICID> <ram:BICID>DE5656565</ram:BICID>
<ram:Name>Commerzbank</ram:Name> <ram:Name>Commerzbank</ram:Name>
</ram:PayeeSpecifiedCreditorFinancialInstitution> </ram:PayeeSpecifiedCreditorFinancialInstitution>
*/ */
ndList = document.getElementsByTagNameNS("*","PayeePartyCreditorFinancialAccount"); //$NON-NLS-1$ ndList = document.getElementsByTagNameNS("*","PayeePartyCreditorFinancialAccount"); //$NON-NLS-1$
@@ -200,7 +210,7 @@ public class ZUGFeRDImporter {
// there are many "name" elements, so get the one below // there are many "name" elements, so get the one below
// SellerTradeParty // SellerTradeParty
NodeList bookingDetails = booking.getChildNodes(); NodeList bookingDetails = booking.getChildNodes();
for (int detailIndex = 0; detailIndex < bookingDetails for (int detailIndex = 0; detailIndex < bookingDetails
.getLength(); detailIndex++) { .getLength(); detailIndex++) {
@@ -208,7 +218,7 @@ public class ZUGFeRDImporter {
if ((detail.getLocalName()!=null)&&(detail.getLocalName().equals("IBANID"))) { //$NON-NLS-1$ if ((detail.getLocalName()!=null)&&(detail.getLocalName().equals("IBANID"))) { //$NON-NLS-1$
setIBAN(detail.getTextContent()); setIBAN(detail.getTextContent());
} }
} }
} }
@@ -266,7 +276,7 @@ public class ZUGFeRDImporter {
if (!amountFound) { if (!amountFound) {
/* there is apparently no requirement to mention DuePayableAmount,, /* there is apparently no requirement to mention DuePayableAmount,,
* if it's not there, check for GrandTotalAmount * if it's not there, check for GrandTotalAmount
*/ */
ndList = document.getElementsByTagNameNS("*","GrandTotalAmount"); //$NON-NLS-1$ ndList = document.getElementsByTagNameNS("*","GrandTotalAmount"); //$NON-NLS-1$
@@ -278,10 +288,28 @@ public class ZUGFeRDImporter {
setAmount(booking.getTextContent()); setAmount(booking.getTextContent());
} }
}
}
ndList = document.getElementsByTagNameNS("*","SpecifiedTradePaymentTerms"); //$NON-NLS-1$
for (int bookingIndex = 0; bookingIndex < ndList
.getLength(); bookingIndex++) {
Node booking = ndList.item(bookingIndex);
// there are many "name" elements, so get the one below
// SellerTradeParty
NodeList bookingDetails = booking.getChildNodes();
for (int detailIndex = 0; detailIndex < bookingDetails
.getLength(); detailIndex++) {
Node detail = bookingDetails.item(detailIndex);
if ((detail.getLocalName()!=null)&&(detail.getLocalName().equals("DueDateDateTime"))) { //$NON-NLS-1$
setDueDate(detail.getTextContent().trim());
}
}
}
parsed=true;
} }
@@ -290,18 +318,24 @@ public class ZUGFeRDImporter {
} }
public String getForeignReference() { public String getForeignReference() {
if (!parsed) {
throw new RuntimeException("use parse() before requesting a value");
}
return foreignReference; return foreignReference;
} }
public void setForeignReference(String foreignReference) { private void setForeignReference(String foreignReference) {
this.foreignReference = foreignReference; this.foreignReference = foreignReference;
} }
public String getBIC() { public String getBIC() {
if (!parsed) {
throw new RuntimeException("use parse() before requesting a value");
}
return BIC; return BIC;
} }
@@ -312,6 +346,11 @@ public class ZUGFeRDImporter {
} }
private void setDueDate(String dueDate) {
this.dueDate = dueDate;
}
private void setBankName(String bankname) { private void setBankName(String bankname) {
this.bankName = bankname; this.bankName = bankname;
} }
@@ -319,23 +358,32 @@ public class ZUGFeRDImporter {
public String getIBAN() { public String getIBAN() {
if (!parsed) {
throw new RuntimeException("use parse() before requesting a value");
}
return IBAN; return IBAN;
} }
public String getBankName() { public String getBankName() {
if (!parsed) {
throw new RuntimeException("use parse() before requesting a value");
}
return bankName; return bankName;
} }
public void setIBAN(String IBAN) { private void setIBAN(String IBAN) {
this.IBAN = IBAN; this.IBAN = IBAN;
} }
public String getHolder() { public String getHolder() {
if (rawXML==null) {
throw new RuntimeException("use parse() before requesting a value");
}
return holder; return holder;
} }
@@ -348,9 +396,18 @@ public class ZUGFeRDImporter {
public String getAmount() { public String getAmount() {
if (rawXML==null) {
throw new RuntimeException("use parse() before requesting a value");
}
return amount; return amount;
} }
public String getDueDate() {
if (rawXML==null) {
throw new RuntimeException("use parse() before requesting a value");
}
return dueDate;
}
private void setAmount(String amount) { private void setAmount(String amount) {
this.amount = amount; this.amount = amount;
@@ -362,7 +419,7 @@ public class ZUGFeRDImporter {
public String getMeta() { public String getMeta() {
if (rawXML==null){ if (rawXML==null){
return null; return null;
} else { } else {
return new String(rawXML); return new String(rawXML);
} }
@@ -372,7 +429,7 @@ public class ZUGFeRDImporter {
/** /**
* Returns the raw XML data as extracted from the ZUGFeRD PDF file. * Returns the raw XML data as extracted from the ZUGFeRD PDF file.
*/ */
public byte[] getRawXML() public byte[] getRawXML()
{ {
return rawXML; return rawXML;
} }
@@ -381,8 +438,8 @@ public class ZUGFeRDImporter {
* will return true if the metadata (just extract-ed or set with setMeta) contains ZUGFeRD XML * will return true if the metadata (just extract-ed or set with setMeta) contains ZUGFeRD XML
* */ * */
public boolean canParse() { public boolean canParse() {
//SpecifiedExchangedDocumentContext is in the schema, so a relatively good indication if zugferd is present - better than just invoice //SpecifiedExchangedDocumentContext is in the schema, so a relatively good indication if zugferd is present - better than just invoice
String meta=getMeta(); String meta=getMeta();
return (meta!=null)&&( meta.length()>0)&&( meta.contains("SpecifiedExchangedDocumentContext")); //$NON-NLS-1$ return (meta!=null)&&( meta.length()>0)&&( meta.contains("SpecifiedExchangedDocumentContext")); //$NON-NLS-1$

View File

@@ -49,7 +49,7 @@ public class MustangReaderWriterEdgeTest extends TestCase implements IZUGFeRDExp
@Override @Override
public String getOwnBIC() public String getOwnBIC()
{ {
return "COBADEFXXX"; return "COBADEFFXXX";
} }
@Override @Override
@@ -118,7 +118,13 @@ public class MustangReaderWriterEdgeTest extends TestCase implements IZUGFeRDExp
{ {
return null; return null;
} }
@Override
public String getCurrency()
{
return "EUR";
}
@Override @Override
public IZUGFeRDExportableItem[] getZFItems() public IZUGFeRDExportableItem[] getZFItems()
{ {
@@ -133,11 +139,6 @@ public class MustangReaderWriterEdgeTest extends TestCase implements IZUGFeRDExp
return allItems; return allItems;
} }
@Override
public String getInvoiceCurrency() {
return "EUR";
}
@Override @Override
public String getOwnPaymentInfoText() { public String getOwnPaymentInfoText() {
return "Überweisung"; return "Überweisung";
@@ -258,7 +259,7 @@ public class MustangReaderWriterEdgeTest extends TestCase implements IZUGFeRDExp
@Override @Override
public IZUGFeRDAllowanceCharge[] getItemAllowances() { public IZUGFeRDAllowanceCharge[] getItemAllowances() {
return null; return null;
} }
@Override @Override
@@ -330,7 +331,7 @@ public class MustangReaderWriterEdgeTest extends TestCase implements IZUGFeRDExp
/** /**
* Create the test case * Create the test case
* *
* @param testName * @param testName
* name of the test case * name of the test case
*/ */
@@ -353,7 +354,7 @@ public class MustangReaderWriterEdgeTest extends TestCase implements IZUGFeRDExp
* The importer test imports from ./src/test/MustangGnuaccountingBeispielRE-20151008_504.pdf to check the values. * The importer test imports from ./src/test/MustangGnuaccountingBeispielRE-20151008_504.pdf to check the values.
* --> as only Name Ascending is supported for Test Unit sequence, I renamed the this test-A-Export to run before * --> as only Name Ascending is supported for Test Unit sequence, I renamed the this test-A-Export to run before
* testZExport * testZExport
* *
* @throws IOException * @throws IOException
*/ */
@@ -368,6 +369,7 @@ public class MustangReaderWriterEdgeTest extends TestCase implements IZUGFeRDExp
String iban = null; String iban = null;
String holder = null; String holder = null;
String ref = null; String ref = null;
String dueDate = null;
if (zi.canParse()) if (zi.canParse())
{ {
@@ -376,6 +378,7 @@ public class MustangReaderWriterEdgeTest extends TestCase implements IZUGFeRDExp
bic = zi.getBIC(); bic = zi.getBIC();
iban = zi.getIBAN(); iban = zi.getIBAN();
holder = zi.getHolder(); holder = zi.getHolder();
dueDate = zi.getDueDate();
ref = zi.getForeignReference(); ref = zi.getForeignReference();
} }
@@ -383,6 +386,8 @@ public class MustangReaderWriterEdgeTest extends TestCase implements IZUGFeRDExp
assertEquals(bic, getOwnBIC()); assertEquals(bic, getOwnBIC());
assertEquals(iban, getOwnIBAN()); assertEquals(iban, getOwnIBAN());
assertEquals(holder, getOwnOrganisationName()); assertEquals(holder, getOwnOrganisationName());
assertEquals(dueDate, "20141029");
assertEquals(ref, getNumber()); assertEquals(ref, getNumber());
} }
@@ -401,16 +406,13 @@ public class MustangReaderWriterEdgeTest extends TestCase implements IZUGFeRDExp
final String TARGET_PDF = "./target/testout-MustangGnuaccountingBeispielRE-20151008_504newEdge.pdf"; final String TARGET_PDF = "./target/testout-MustangGnuaccountingBeispielRE-20151008_504newEdge.pdf";
// the writing part // the writing part
PDDocument doc;
try try
{ {
doc = PDDocument.load(SOURCE_PDF);
// automatically add Zugferd to all outgoing invoices // automatically add Zugferd to all outgoing invoices
ZUGFeRDExporter ze = new ZUGFeRDExporter(); ZUGFeRDExporter ze = new ZUGFeRDExporter();
ze.PDFmakeA3compliant(doc, "My Application", System.getProperty("user.name"), true); ze.PDFmakeA3compliant(SOURCE_PDF, "My Application", System.getProperty("user.name"), true);
ze.PDFattachZugferdFile(doc, this); ze.PDFattachZugferdFile(this);
doc.save(TARGET_PDF); ze.export(TARGET_PDF);
doc.close();
} }
catch (IOException e) catch (IOException e)
{ {

View File

@@ -49,7 +49,7 @@ public class MustangReaderWriterTest extends TestCase implements IZUGFeRDExporta
@Override @Override
public String getOwnBIC() public String getOwnBIC()
{ {
return "COBADEFXXX"; return "COBADEFFXXX";
} }
@Override @Override
@@ -118,6 +118,12 @@ public class MustangReaderWriterTest extends TestCase implements IZUGFeRDExporta
return null; return null;
} }
@Override
public String getCurrency()
{
return "EUR";
}
@Override @Override
public IZUGFeRDExportableItem[] getZFItems() public IZUGFeRDExportableItem[] getZFItems()
{ {
@@ -132,11 +138,6 @@ public class MustangReaderWriterTest extends TestCase implements IZUGFeRDExporta
return allItems; return allItems;
} }
@Override
public String getInvoiceCurrency() {
return "EUR";
}
@Override @Override
public String getOwnPaymentInfoText() { public String getOwnPaymentInfoText() {
return "Überweisung"; return "Überweisung";
@@ -257,16 +258,16 @@ public class MustangReaderWriterTest extends TestCase implements IZUGFeRDExporta
{ {
this.product = product; this.product = product;
} }
@Override @Override
public IZUGFeRDAllowanceCharge[] getItemAllowances() { public IZUGFeRDAllowanceCharge[] getItemAllowances() {
return null; return null;
} }
@Override @Override
public IZUGFeRDAllowanceCharge[] getItemCharges() { public IZUGFeRDAllowanceCharge[] getItemCharges() {
return null; return null;
} }
} }
@@ -332,7 +333,7 @@ public class MustangReaderWriterTest extends TestCase implements IZUGFeRDExporta
/** /**
* Create the test case * Create the test case
* *
* @param testName * @param testName
* name of the test case * name of the test case
*/ */
@@ -355,7 +356,7 @@ public class MustangReaderWriterTest extends TestCase implements IZUGFeRDExporta
* The importer test imports from ./src/test/MustangGnuaccountingBeispielRE-20151008_504.pdf to check the values. * The importer test imports from ./src/test/MustangGnuaccountingBeispielRE-20151008_504.pdf to check the values.
* --> as only Name Ascending is supported for Test Unit sequence, I renamed the this test-A-Export to run before * --> as only Name Ascending is supported for Test Unit sequence, I renamed the this test-A-Export to run before
* testZExport * testZExport
* *
* @throws IOException * @throws IOException
*/ */
@@ -403,16 +404,13 @@ public class MustangReaderWriterTest extends TestCase implements IZUGFeRDExporta
final String TARGET_PDF = "./target/testout-MustangGnuaccountingBeispielRE-20151008_504new.pdf"; final String TARGET_PDF = "./target/testout-MustangGnuaccountingBeispielRE-20151008_504new.pdf";
// the writing part // the writing part
PDDocument doc;
try try
{ {
doc = PDDocument.load(SOURCE_PDF);
// automatically add Zugferd to all outgoing invoices // automatically add Zugferd to all outgoing invoices
ZUGFeRDExporter ze = new ZUGFeRDExporter(); ZUGFeRDExporter ze = new ZUGFeRDExporter();
ze.PDFmakeA3compliant(doc, "My Application", System.getProperty("user.name"), true); ze.PDFmakeA3compliant(SOURCE_PDF, "My Application", System.getProperty("user.name"), true);
ze.PDFattachZugferdFile(doc, this); ze.PDFattachZugferdFile(this);
doc.save(TARGET_PDF); ze.export(TARGET_PDF);
doc.close();
} }
catch (IOException e) catch (IOException e)
{ {

View File

@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.mustangproject.ZUGFeRD</groupId> <groupId>org.mustangproject.ZUGFeRD</groupId>
<artifactId>toecount</artifactId> <artifactId>toecount</artifactId>
<version>0.0.6-SNAPSHOT</version> <version>0.0.8-SNAPSHOT</version>
<name>ZUGFeRD PDF checker</name> <name>ZUGFeRD PDF checker</name>
<description>Shows statistics on how many PDFs in a directory are ZUGFeRD-Compliant</description> <description>Shows statistics on how many PDFs in a directory are ZUGFeRD-Compliant</description>
<repositories> <repositories>
@@ -27,7 +27,7 @@
<dependency> <dependency>
<groupId>org.mustangproject.ZUGFeRD</groupId> <groupId>org.mustangproject.ZUGFeRD</groupId>
<artifactId>mustang</artifactId> <artifactId>mustang</artifactId>
<version>1.2.1-SNAPSHOT</version> <version>1.3.0-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.pdfbox</groupId> <groupId>org.apache.pdfbox</groupId>

View File

@@ -30,11 +30,34 @@ public class FileChecker {
return false; return false;
} }
ZUGFeRDImporter zi=new ZUGFeRDImporter(); ZUGFeRDImporter zi=new ZUGFeRDImporter();
zi.extract(filename); try {
if (zi.canParse()) { zi.extract(filename);
thisRun.incZUGFeRDCount(); if (zi.canParse()) {
return true; thisRun.incZUGFeRDCount();
} else { return true;
} else {
return false;
}
} catch (NullPointerException e) {
// something really rare happened -- corrupted ZF?
/***
* e.g. Exception in thread "main" java.lang.NullPointerException
at org.mustangproject.ZUGFeRD.ZUGFeRDImporter.extractLowLevel(ZUGFeRDImporter.java:90)
at org.mustangproject.ZUGFeRD.ZUGFeRDImporter.extract(ZUGFeRDImporter.java:64)
at toecount.FileChecker.checkForZUGFeRD(FileChecker.java:33)
at toecount.Toecount.main(Toecount.java:111)
*
*/
// Ignore nevertheless, most likely we're batch processing
return false;
} catch (Exception e2) {
/**
* probably thrown up from
AM org.apache.pdfbox.pdfparser.PDFParser parse, most likely
INFORMATION: Document is encrypted
but also other internal PDF errors possible like
..Okt 23, 2015 11:17:53 AM org.apache.pdfbox.pdfparser.XrefTrailerResolver setStartxref
*/
return false; return false;
} }
} }

View File

@@ -22,7 +22,7 @@ public class Toecount {
} }
private static void printHelp() { private static void printHelp() {
System.out System.out
.println("Mustangproject.org's Toecount 0.0.6 \r\n" .println("Mustangproject.org's Toecount 0.0.7 \r\n"
+ "A Apache Public License command line tool for statistics on PDF invoices with\r\n" + "A Apache Public License command line tool for statistics on PDF invoices with\r\n"
+ "ZUGFeRD Metadata (http://www.zugferd.de)\r\n" + "ZUGFeRD Metadata (http://www.zugferd.de)\r\n"
+ "\r\n" + "\r\n"

View File

@@ -3,8 +3,8 @@
<parent> <parent>
<groupId>com.github.rayman2200</groupId> <groupId>com.github.rayman2200</groupId>
<artifactId>mustang-sample-project</artifactId> <artifactId>mustang-sample-project</artifactId>
<version>1.3.0-SNAPSHOT</version> <version>1.3.0.1-SNAPSHOT</version>
</parent> </parent>
<artifactId>pdfa3-samples</artifactId> <artifactId>pdfa3-samples</artifactId>
</project> </project>

View File

@@ -30,6 +30,7 @@ import org.apache.jempbox.xmp.XMPSchemaBasic;
import org.apache.jempbox.xmp.XMPSchemaDublinCore; import org.apache.jempbox.xmp.XMPSchemaDublinCore;
import org.apache.jempbox.xmp.XMPSchemaPDF; import org.apache.jempbox.xmp.XMPSchemaPDF;
import org.apache.jempbox.xmp.pdfa.XMPSchemaPDFAId; import org.apache.jempbox.xmp.pdfa.XMPSchemaPDFAId;
import org.apache.pdfbox.cos.COSArray;
import org.apache.pdfbox.cos.COSDictionary; import org.apache.pdfbox.cos.COSDictionary;
import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDDocumentCatalog; import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
@@ -120,6 +121,10 @@ public class PDFA3FileAttachment
// cosArray.add(fs); // cosArray.add(fs);
// catalog.setItem("AF", cosArray); // catalog.setItem("AF", cosArray);
COSDictionary dict2 = catalog.getCOSDictionary();
COSArray array = new COSArray();
array.add(fs.getCOSDictionary()); // see below
dict2.setItem("AF",array);
} }
/** /**

26
pom.xml
View File

@@ -2,13 +2,13 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.github.rayman2200</groupId> <groupId>com.github.rayman2200</groupId>
<artifactId>mustang-sample-project</artifactId> <artifactId>mustang-sample-project</artifactId>
<version>1.3.0-SNAPSHOT</version> <version>1.3.3-SNAPSHOT</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<scm> <scm>
<connection>scm:git:https://github.com/AlexanderSchmidt/PDFA3.git</connection> <connection>scm:git:https://github.com/jstaerk/mustangproject.git</connection>
<developerConnection>scm:git:https://github.com/AlexanderSchmidt/PDFA3.git</developerConnection> <developerConnection>scm:git:https://github.com/jstaerk/mustangproject.git</developerConnection>
<url>https://github.com/AlexanderSchmidt/PDFA3.git</url> <url>https://github.com/jstaerk/mustangproject</url>
<tag>HEAD</tag> <tag>HEAD</tag>
</scm> </scm>
@@ -24,6 +24,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<github.global.server>github</github.global.server> <github.global.server>github</github.global.server>
<additionalparam>-Xdoclint:none</additionalparam><!-- Skip error check for javadoc --> <additionalparam>-Xdoclint:none</additionalparam><!-- Skip error check for javadoc -->
<maven.compiler.compilerVersion>1.6</maven.compiler.compilerVersion>
</properties> </properties>
<modules> <modules>
@@ -35,7 +36,7 @@
<dependency> <dependency>
<groupId>org.apache.pdfbox</groupId> <groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId> <artifactId>pdfbox</artifactId>
<version>1.8.10</version> <version>1.8.8</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
@@ -47,15 +48,6 @@
<build> <build>
<plugins> <plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin> <plugin>
<artifactId>maven-deploy-plugin</artifactId> <artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version> <version>2.8.2</version>
@@ -76,8 +68,8 @@
<include>**/*</include> <include>**/*</include>
</includes> </includes>
<merge>true</merge> <merge>true</merge>
<repositoryName>PDFA3</repositoryName> <!-- github repo name --> <repositoryName>mustangproject</repositoryName> <!-- github repo name -->
<repositoryOwner>AlexanderSchmidt</repositoryOwner> <!-- github username --> <repositoryOwner>jstaerk</repositoryOwner> <!-- github username -->
</configuration> </configuration>
<executions> <executions>
<!-- run site-maven-plugin's 'site' target as part of the build's normal <!-- run site-maven-plugin's 'site' target as part of the build's normal
@@ -92,4 +84,4 @@
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
</project> </project>