updated filename, PDF/A schema extension for ZF2

This commit is contained in:
Jochen Stärk
2017-10-07 17:48:00 +02:00
parent 55206e7e89
commit a4e6f06e7d
8 changed files with 164 additions and 132 deletions

View File

@@ -4,7 +4,7 @@
<groupId>org.mustangproject.ZUGFeRD</groupId> <groupId>org.mustangproject.ZUGFeRD</groupId>
<artifactId>mustang</artifactId> <artifactId>mustang</artifactId>
<name>Mustang</name> <name>Mustang</name>
<version>1.4.1-SNAPSHOT</version> <version>1.4.2-SNAPSHOT</version>
<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>
<mailingLists> <mailingLists>

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>mustang</artifactId> <artifactId>mustang</artifactId>
<version>1.4.1-SNAPSHOT</version> <version>1.4.2-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>

View File

@@ -39,6 +39,15 @@ public class XMPSchemaPDFAExtensions extends PDFAExtensionSchema {
public final String prefix_pdfaSchema = "pdfaSchema"; public final String prefix_pdfaSchema = "pdfaSchema";
public final String xmlns_pdfaProperty = "http://www.aiim.org/pdfa/ns/property#"; public final String xmlns_pdfaProperty = "http://www.aiim.org/pdfa/ns/property#";
public final String prefix_pdfaProperty = "pdfaProperty"; public final String prefix_pdfaProperty = "pdfaProperty";
public String namespace = null;
public String prefix = null;
public void setZUGFeRDVersion(int ver) {
namespace=ZUGFeRDExporter.getNamespaceForVersion(ver);
prefix=ZUGFeRDExporter.getPrefixForVersion(ver);
}
private DefinedStructuredType addProperty(ArrayProperty parent, String name, String type, String category, private DefinedStructuredType addProperty(ArrayProperty parent, String name, String type, String category,
String description) { String description) {
@@ -68,17 +77,15 @@ public class XMPSchemaPDFAExtensions extends PDFAExtensionSchema {
} }
public XMPSchemaPDFAExtensions(XMPMetadata metadata) { public XMPSchemaPDFAExtensions(XMPMetadata metadata) {
super(metadata); super(metadata);
setZUGFeRDVersion(2);
attachExtensions(metadata, true); attachExtensions(metadata, true);
} }
public XMPSchemaPDFAExtensions(XMPMetadata metadata, boolean withZF) { public XMPSchemaPDFAExtensions(XMPMetadata metadata, boolean withZF) {
super(metadata); super(metadata);
setZUGFeRDVersion(2);
attachExtensions(metadata, withZF); attachExtensions(metadata, withZF);
} }
public void attachExtensions(XMPMetadata metadata, boolean withZF) { public void attachExtensions(XMPMetadata metadata, boolean withZF) {
@@ -98,10 +105,10 @@ public class XMPSchemaPDFAExtensions extends PDFAExtensionSchema {
li.addProperty(pdfa1); li.addProperty(pdfa1);
pdfa1 = new TextType(metadata, xmlns_pdfaSchema, prefix_pdfaSchema, PDFASchemaType.NAMESPACE_URI, pdfa1 = new TextType(metadata, xmlns_pdfaSchema, prefix_pdfaSchema, PDFASchemaType.NAMESPACE_URI,
"urn:ferd:pdfa:CrossIndustryDocument:invoice:1p0#"); namespace);
li.addProperty(pdfa1); li.addProperty(pdfa1);
pdfa1 = new TextType(metadata, xmlns_pdfaSchema, prefix_pdfaSchema, PDFASchemaType.PREFIX, "zf"); pdfa1 = new TextType(metadata, xmlns_pdfaSchema, prefix_pdfaSchema, PDFASchemaType.PREFIX, prefix);
li.addProperty(pdfa1); li.addProperty(pdfa1);
ArrayProperty newSeq = new ArrayProperty(metadata, xmlns_pdfaSchema, prefix_pdfaSchema, ArrayProperty newSeq = new ArrayProperty(metadata, xmlns_pdfaSchema, prefix_pdfaSchema,
@@ -112,7 +119,7 @@ public class XMPSchemaPDFAExtensions extends PDFAExtensionSchema {
addProperty(newSeq, "DocumentType", "Text", "external", "INVOICE"); addProperty(newSeq, "DocumentType", "Text", "external", "INVOICE");
addProperty(newSeq, "Version", "Text", "external", "The actual version of the ZUGFeRD XML schema"); addProperty(newSeq, "Version", "Text", "external", "The actual version of the ZUGFeRD XML schema");
addProperty(newSeq, "ConformanceLevel", "Text", "external", addProperty(newSeq, "ConformanceLevel", "Text", "external",
"The conformance level of the embedded ZUGFeRD data"); "The selected ZUGFeRD profile completeness");
} }
} }
} }

View File

@@ -15,14 +15,14 @@ public class XMPSchemaZugferd extends XMPSchema {
/** /**
* This is what needs to be added to the RDF metadata - basically the name of the embedded Zugferd file * This is what needs to be added to the RDF metadata - basically the name of the embedded Zugferd file
*/ */
public XMPSchemaZugferd(XMPMetadata metadata, ZUGFeRDConformanceLevel conformanceLevel) { public XMPSchemaZugferd(XMPMetadata metadata, ZUGFeRDConformanceLevel conformanceLevel, String URN, String prefix, String filename) {
super(metadata, "urn:ferd:pdfa:CrossIndustryDocument:invoice:1p0#", "zf", "ZUGFeRD Schema"); super(metadata, URN, prefix, "ZUGFeRD Schema");
setAboutAsSimple(""); setAboutAsSimple("");
setTextPropertyValue("ConformanceLevel", conformanceLevel.name()); setTextPropertyValue("ConformanceLevel", conformanceLevel.name());
setTextPropertyValue("DocumentType", "INVOICE"); setTextPropertyValue("DocumentType", "INVOICE");
setTextPropertyValue("DocumentFileName", "ZUGFeRD-invoice.xml"); setTextPropertyValue("DocumentFileName", filename);
setTextPropertyValue("Version", "1.0"); setTextPropertyValue("Version", "1.0");
} }
} }

View File

@@ -35,11 +35,10 @@ import java.util.Map;
public class ZUGFeRDExporter implements Closeable { public class ZUGFeRDExporter implements Closeable {
/** /**
* * You will need Apache PDFBox. To use the ZUGFeRD exporter, implement * To use the ZUGFeRD exporter, implement IZUGFeRDExportableTransaction in
* IZUGFeRDExportableTransaction in yourTransaction (which will require you * yourTransaction (which will require you to implement Product, Item and
* to implement Product, Item and Contact) then call doc = * Contact) then call doc = PDDocument.load(PDFfilename); // automatically add
* PDDocument.load(PDFfilename); // automatically add Zugferd to all * Zugferd to all outgoing invoices ZUGFeRDExporter ze = new ZUGFeRDExporter();
* outgoing invoices ZUGFeRDExporter ze = new ZUGFeRDExporter();
* ze.PDFmakeA3compliant(doc, "Your application name", * ze.PDFmakeA3compliant(doc, "Your application name",
* System.getProperty("user.name"), true); ze.PDFattachZugferdFile(doc, * System.getProperty("user.name"), true); ze.PDFattachZugferdFile(doc,
* yourTransaction); * yourTransaction);
@@ -47,67 +46,102 @@ public class ZUGFeRDExporter implements Closeable {
* doc.save(PDFfilename); * doc.save(PDFfilename);
* *
* @author jstaerk * @author jstaerk
* @deprecated Use the factory methods {@link #createFromPDFA3(String)}, {@link #createFromPDFA3(InputStream)} or * @deprecated Use the factory methods {@link #createFromPDFA3(String)},
* the {@link ZUGFeRDExporterFromA1Factory} instead * {@link #createFromPDFA3(InputStream)} or the
* {@link ZUGFeRDExporterFromA1Factory} instead
* *
*/ */
// // MAIN CLASS
@Deprecated
private PDFAConformanceLevel conformanceLevel = PDFAConformanceLevel.UNICODE;
// BASIC, COMFORT etc - may be set from outside.
@Deprecated
private ZUGFeRDConformanceLevel zUGFeRDConformanceLevel = ZUGFeRDConformanceLevel.EXTENDED;
/**
* Data (XML invoice) to be added to the ZUGFeRD PDF. It may be externally set,
* in which case passing a IZUGFeRDExportableTransaction is not necessary. By
* default it is null meaning the caller needs to pass a
* IZUGFeRDExportableTransaction for the XML to be populated.
*/
IXMLProvider xmlProvider;
@Deprecated
private boolean ignoreA1Errors;
private PDDocument doc;
int ZFVersion;
public ZUGFeRDExporter() { public ZUGFeRDExporter() {
init(); init();
} }
public ZUGFeRDExporter(PDDocument doc2) { public ZUGFeRDExporter(PDDocument doc2) {
doc=doc2; doc = doc2;
init(); init();
} }
public void setVersion(int ver) { public static String getNamespaceForVersion(int ver) {
if (ver==1) { if (ver == 1) {
ZUGFeRD1PullProvider z1p =new ZUGFeRD1PullProvider(); return "urn:ferd:pdfa:CrossIndustryDocument:invoice:1p0#";
this.xmlProvider=z1p; } else if (ver == 2) {
return "urn:factur-x:pdfa:CrossIndustryDocument:invoice:1p0#";
} else { } else {
ZUGFeRD2PullProvider z2p =new ZUGFeRD2PullProvider(); throw new IllegalArgumentException("Version not supported");
this.xmlProvider=z2p;
} }
} }
private void init() { public static String getPrefixForVersion(int ver) {
setVersion(2); if (ver == 1) {
return "zf";
} else if (ver == 2) {
return "fx";
} else {
throw new IllegalArgumentException("Version not supported");
}
} }
// // MAIN CLASS
@Deprecated
private PDFAConformanceLevel conformanceLevel = PDFAConformanceLevel.UNICODE;
// BASIC, COMFORT etc - may be set from outside. public static String getFilenameForVersion(int ver) {
@Deprecated if (ver == 1) {
private ZUGFeRDConformanceLevel zUGFeRDConformanceLevel = ZUGFeRDConformanceLevel.EXTENDED; return "ZUGFeRD-invoice.xml";
} else if (ver == 2) {
return "factur-x.xml";
} else {
throw new IllegalArgumentException("Version not supported");
}
}
/** public void setZUGFeRDVersion(int ver) {
* Data (XML invoice) to be added to the ZUGFeRD PDF. It may be externally if (ver == 1) {
* set, in which case passing a IZUGFeRDExportableTransaction is not ZUGFeRD1PullProvider z1p = new ZUGFeRD1PullProvider();
* necessary. By default it is null meaning the caller needs to pass a this.xmlProvider = z1p;
* IZUGFeRDExportableTransaction for the XML to be populated. } else if (ver == 2) {
*/ ZUGFeRD2PullProvider z2p = new ZUGFeRD2PullProvider();
IXMLProvider xmlProvider; this.xmlProvider = z2p;
@Deprecated } else {
private boolean ignoreA1Errors; throw new IllegalArgumentException("Version not supported");
private PDDocument doc; }
ZFVersion = ver;
}
private void init() {
setZUGFeRDVersion(2);
}
/** /**
* All files are PDF/A-3, setConformance refers to the level conformance. * All files are PDF/A-3, setConformance refers to the level conformance.
* *
* PDF/A-3 has three conformance levels, called "A", "U" and "B". * PDF/A-3 has three conformance levels, called "A", "U" and "B".
* *
* PDF/A-3-B where B means only visually preservable, U -standard for * PDF/A-3-B where B means only visually preservable, U -standard for Mustang-
* Mustang- means visually and unicode preservable and A means full * means visually and unicode preservable and A means full compliance, i.e.
* compliance, i.e. visually, unicode and structurally preservable and * visually, unicode and structurally preservable and tagged PDF, i.e. useful
* tagged PDF, i.e. useful metainformation for blind people. * metainformation for blind people.
* *
* Feel free to pass "A" as new level if you know what you are doing :-) * Feel free to pass "A" as new level if you know what you are doing :-)
* *
* @deprecated Use {@link ZUGFeRDExporterFromA1Factory} instead * @deprecated Use {@link ZUGFeRDExporterFromA1Factory} instead
*/ */
@Deprecated @Deprecated
public void setConformanceLevel(PDFAConformanceLevel newLevel) { public void setConformanceLevel(PDFAConformanceLevel newLevel) {
if (newLevel == null) { if (newLevel == null) {
throw new NullPointerException("pdf conformance level"); throw new NullPointerException("pdf conformance level");
@@ -120,14 +154,16 @@ public class ZUGFeRDExporter implements Closeable {
* *
* PDF/A-3 has three conformance levels, called "A", "U" and "B". * PDF/A-3 has three conformance levels, called "A", "U" and "B".
* *
* PDF/A-3-B where B means only visually preservable, U -standard for * PDF/A-3-B where B means only visually preservable, U -standard for Mustang-
* Mustang- means visually and unicode preservable and A means full * means visually and unicode preservable and A means full compliance, i.e.
* compliance, i.e. visually, unicode and structurally preservable and * visually, unicode and structurally preservable and tagged PDF, i.e. useful
* tagged PDF, i.e. useful metainformation for blind people. * metainformation for blind people.
* *
* Feel free to pass "A" as new level if you know what you are doing :-) * Feel free to pass "A" as new level if you know what you are doing :-)
* *
* @deprecated Use {@link #setConformanceLevel(org.mustangproject.ZUGFeRD.PDFAConformanceLevel)} instead * @deprecated Use
* {@link #setConformanceLevel(org.mustangproject.ZUGFeRD.PDFAConformanceLevel)}
* instead
*/ */
@Deprecated @Deprecated
public void setConformanceLevel(String newLevel) { public void setConformanceLevel(String newLevel) {
@@ -142,29 +178,30 @@ public class ZUGFeRDExporter implements Closeable {
xmlProvider.setTest(); xmlProvider.setTest();
} }
/** /**
* @deprecated Use {@link ZUGFeRDExporterFromA1Factory} instead * @deprecated Use {@link ZUGFeRDExporterFromA1Factory} instead
*/ */
@Deprecated @Deprecated
public void ignoreA1Errors() { public void ignoreA1Errors() {
ignoreA1Errors = true; ignoreA1Errors = true;
} }
/** /**
* @deprecated Use the factory method {@link #createFromPDFA3(String)} instead * @deprecated Use the factory method {@link #createFromPDFA3(String)} instead
*/ */
@Deprecated @Deprecated
public void loadPDFA3(String filename) throws IOException { public void loadPDFA3(String filename) throws IOException {
doc = PDDocument.load(new File(filename)); doc = PDDocument.load(new File(filename));
} }
public static ZUGFeRDExporter createFromPDFA3(String filename) throws IOException { public static ZUGFeRDExporter createFromPDFA3(String filename) throws IOException {
return new ZUGFeRDExporter(PDDocument.load(new File(filename))); return new ZUGFeRDExporter(PDDocument.load(new File(filename)));
} }
/** /**
* @deprecated Use the factory method {@link #createFromPDFA3(InputStream)} instead * @deprecated Use the factory method {@link #createFromPDFA3(InputStream)}
*/ * instead
*/
@Deprecated @Deprecated
public void loadPDFA3(InputStream file) throws IOException { public void loadPDFA3(InputStream file) throws IOException {
doc = PDDocument.load(file); doc = PDDocument.load(file);
@@ -175,40 +212,31 @@ public class ZUGFeRDExporter implements Closeable {
} }
/** /**
* Makes A PDF/A3a-compliant document from a PDF-A1 compliant document (on * Makes A PDF/A3a-compliant document from a PDF-A1 compliant document (on the
* the metadata level, this will not e.g. convert graphics to JPG-2000) * metadata level, this will not e.g. convert graphics to JPG-2000)
* *
* @deprecated use the {@link ZUGFeRDExporterFromA1Factory} instead * @deprecated use the {@link ZUGFeRDExporterFromA1Factory} instead
* *
*/ */
@Deprecated @Deprecated
public PDDocumentCatalog PDFmakeA3compliant(String filename, public PDDocumentCatalog PDFmakeA3compliant(String filename, String producer, String creator,
String producer, String creator, boolean attachZugferdHeaders) boolean attachZugferdHeaders) throws IOException, TransformerException {
throws IOException, TransformerException {
doc = createPDFA1Factory() doc = createPDFA1Factory().setProducer(producer).setCreator(creator)
.setProducer(producer) .setAttachZUGFeRDHeaders(attachZugferdHeaders).load(filename).doc;
.setCreator(creator)
.setAttachZUGFeRDHeaders(attachZugferdHeaders)
.load(filename)
.doc;
return doc.getDocumentCatalog(); return doc.getDocumentCatalog();
} }
/** /**
* @deprecated use the {@link ZUGFeRDExporterFromA1Factory} instead * @deprecated use the {@link ZUGFeRDExporterFromA1Factory} instead
*/ */
@Deprecated @Deprecated
public PDDocumentCatalog PDFmakeA3compliant(InputStream file, public PDDocumentCatalog PDFmakeA3compliant(InputStream file, String producer, String creator,
String producer, String creator, boolean attachZugferdHeaders) throws IOException, TransformerException { boolean attachZugferdHeaders) throws IOException, TransformerException {
doc = createPDFA1Factory() doc = createPDFA1Factory().setProducer(producer).setCreator(creator)
.setProducer(producer) .setAttachZUGFeRDHeaders(attachZugferdHeaders).load(file).doc;
.setCreator(creator)
.setAttachZUGFeRDHeaders(attachZugferdHeaders)
.load(file)
.doc;
return doc.getDocumentCatalog(); return doc.getDocumentCatalog();
} }
@@ -218,9 +246,7 @@ public class ZUGFeRDExporter implements Closeable {
if (ignoreA1Errors) { if (ignoreA1Errors) {
factory.ignorePDFAErrors(); factory.ignorePDFAErrors();
} }
return factory return factory.setZUGFeRDConformanceLevel(zUGFeRDConformanceLevel).setConformanceLevel(conformanceLevel);
.setZUGFeRDConformanceLevel(zUGFeRDConformanceLevel)
.setConformanceLevel(conformanceLevel);
} }
@Override @Override
@@ -230,33 +256,28 @@ public class ZUGFeRDExporter implements Closeable {
} }
} }
/** /**
* Embeds the Zugferd XML structure in a file named ZUGFeRD-invoice.xml. * Embeds the Zugferd XML structure in a file named ZUGFeRD-invoice.xml.
* *
* @param trans * @param trans
* a IZUGFeRDExportableTransaction that provides the data-model * a IZUGFeRDExportableTransaction that provides the data-model to
* to populate the XML. This parameter may be null, if so the XML * populate the XML. This parameter may be null, if so the XML data
* data should hav ebeen set via * should hav ebeen set via
* <code>setZUGFeRDXMLData(byte[] zugferdData)</code> * <code>setZUGFeRDXMLData(byte[] zugferdData)</code>
*/ */
public void PDFattachZugferdFile(IZUGFeRDExportableTransaction trans) public void PDFattachZugferdFile(IZUGFeRDExportableTransaction trans) throws IOException {
throws IOException {
xmlProvider.generateXML(trans); xmlProvider.generateXML(trans);
String filename = getFilenameForVersion(ZFVersion);
PDFAttachGenericFile( PDFAttachGenericFile(doc, filename, "Alternative",
doc, "Invoice metadata conforming to ZUGFeRD standard (http://www.ferd-net.de/front_content.php?idcat=231&lang=4)",
"ZUGFeRD-invoice.xml", "text/xml", xmlProvider.getXML());
"Alternative",
"Invoice metadata conforming to ZUGFeRD standard (http://www.ferd-net.de/front_content.php?idcat=231&lang=4)",
"text/xml", xmlProvider.getXML());
} }
public void export(String ZUGFeRDfilename) throws IOException { public void export(String ZUGFeRDfilename) throws IOException {
doc.save(ZUGFeRDfilename); doc.save(ZUGFeRDfilename);
} }
public void export(OutputStream output) throws IOException { public void export(OutputStream output) throws IOException {
doc.save(output); doc.save(output);
} }
@@ -278,13 +299,11 @@ public class ZUGFeRDExporter implements Closeable {
* the binary data of the file/attachment * the binary data of the file/attachment
* @throws java.io.IOException * @throws java.io.IOException
*/ */
public void PDFAttachGenericFile(PDDocument doc, String filename, public void PDFAttachGenericFile(PDDocument doc, String filename, String relationship, String description,
String relationship, String description, String subType, byte[] data) String subType, byte[] data) throws IOException {
throws IOException {
PDComplexFileSpecification fs = new PDComplexFileSpecification(); PDComplexFileSpecification fs = new PDComplexFileSpecification();
fs.setFile(filename); fs.setFile(filename);
COSDictionary dict = fs.getCOSObject(); COSDictionary dict = fs.getCOSObject();
dict.setName("AFRelationship", relationship); dict.setName("AFRelationship", relationship);
dict.setString("UF", filename); dict.setString("UF", filename);
@@ -302,14 +321,12 @@ public class ZUGFeRDExporter implements Closeable {
// In addition make sure the embedded file is set under /UF // In addition make sure the embedded file is set under /UF
dict = fs.getCOSObject(); dict = fs.getCOSObject();
COSDictionary efDict = (COSDictionary) dict COSDictionary efDict = (COSDictionary) dict.getDictionaryObject(COSName.EF);
.getDictionaryObject(COSName.EF);
COSBase lowerLevelFile = efDict.getItem(COSName.F); COSBase lowerLevelFile = efDict.getItem(COSName.F);
efDict.setItem(COSName.UF, lowerLevelFile); efDict.setItem(COSName.UF, lowerLevelFile);
// now add the entry to the embedded file tree and set in the document. // now add the entry to the embedded file tree and set in the document.
PDDocumentNameDictionary names = new PDDocumentNameDictionary( PDDocumentNameDictionary names = new PDDocumentNameDictionary(doc.getDocumentCatalog());
doc.getDocumentCatalog());
PDEmbeddedFilesNameTreeNode efTree = names.getEmbeddedFiles(); PDEmbeddedFilesNameTreeNode efTree = names.getEmbeddedFiles();
if (efTree == null) { if (efTree == null) {
efTree = new PDEmbeddedFilesNameTreeNode(); efTree = new PDEmbeddedFilesNameTreeNode();
@@ -330,8 +347,7 @@ public class ZUGFeRDExporter implements Closeable {
doc.getDocumentCatalog().setNames(names); doc.getDocumentCatalog().setNames(names);
// AF entry (Array) in catalog with the FileSpec // AF entry (Array) in catalog with the FileSpec
COSArray cosArray = (COSArray) doc.getDocumentCatalog() COSArray cosArray = (COSArray) doc.getDocumentCatalog().getCOSObject().getItem("AF");
.getCOSObject().getItem("AF");
if (cosArray == null) { if (cosArray == null) {
cosArray = new COSArray(); cosArray = new COSArray();
} }
@@ -339,22 +355,22 @@ public class ZUGFeRDExporter implements Closeable {
COSDictionary dict2 = doc.getDocumentCatalog().getCOSObject(); COSDictionary dict2 = doc.getDocumentCatalog().getCOSObject();
COSArray array = new COSArray(); COSArray array = new COSArray();
array.add(fs.getCOSObject()); // see below array.add(fs.getCOSObject()); // see below
dict2.setItem("AF",array); dict2.setItem("AF", array);
doc.getDocumentCatalog().getCOSObject().setItem("AF", cosArray); doc.getDocumentCatalog().getCOSObject().setItem("AF", cosArray);
} }
/** /**
* Sets the ZUGFeRD XML data to be attached as a single byte array. This is * Sets the ZUGFeRD XML data to be attached as a single byte array. This is
* useful for use-cases where the XML has already been produced by some * useful for use-cases where the XML has already been produced by some external
* external API or component. * API or component.
* *
* @param zugferdData * @param zugferdData
* XML data to be set as a byte array (XML file in raw form). * XML data to be set as a byte array (XML file in raw form).
*/ */
public void setZUGFeRDXMLData(byte[] zugferdData) throws IOException { public void setZUGFeRDXMLData(byte[] zugferdData) throws IOException {
CustomXMLProvider cus =new CustomXMLProvider(); CustomXMLProvider cus = new CustomXMLProvider();
cus.setXML(zugferdData); cus.setXML(zugferdData);
this.xmlProvider=cus; this.xmlProvider = cus;
PDFattachZugferdFile(null); PDFattachZugferdFile(null);
} }
@@ -363,8 +379,8 @@ public class ZUGFeRDExporter implements Closeable {
* *
* @param zUGFeRDConformanceLevel * @param zUGFeRDConformanceLevel
* the new conformance level * the new conformance level
* *
* @deprecated Use {@link ZUGFeRDExporterFromA1Factory} instead * @deprecated Use {@link ZUGFeRDExporterFromA1Factory} instead
*/ */
@Deprecated @Deprecated
public void setZUGFeRDConformanceLevel(ZUGFeRDConformanceLevel zUGFeRDConformanceLevel) { public void setZUGFeRDConformanceLevel(ZUGFeRDConformanceLevel zUGFeRDConformanceLevel) {

View File

@@ -9,13 +9,11 @@ import org.apache.pdfbox.preflight.PreflightDocument;
import org.apache.pdfbox.preflight.exception.ValidationException; import org.apache.pdfbox.preflight.exception.ValidationException;
import org.apache.pdfbox.preflight.parser.PreflightParser; import org.apache.pdfbox.preflight.parser.PreflightParser;
import org.apache.pdfbox.preflight.utils.ByteArrayDataSource; import org.apache.pdfbox.preflight.utils.ByteArrayDataSource;
import org.apache.pdfbox.util.Version;
import org.apache.xmpbox.XMPMetadata; import org.apache.xmpbox.XMPMetadata;
import org.apache.xmpbox.schema.AdobePDFSchema; import org.apache.xmpbox.schema.AdobePDFSchema;
import org.apache.xmpbox.schema.DublinCoreSchema; import org.apache.xmpbox.schema.DublinCoreSchema;
import org.apache.xmpbox.schema.PDFAIdentificationSchema; import org.apache.xmpbox.schema.PDFAIdentificationSchema;
import org.apache.xmpbox.schema.XMPBasicSchema; import org.apache.xmpbox.schema.XMPBasicSchema;
import org.apache.xmpbox.type.BadFieldValueException;
import org.apache.xmpbox.xml.XmpSerializer; import org.apache.xmpbox.xml.XmpSerializer;
import javax.activation.DataSource; import javax.activation.DataSource;
@@ -28,6 +26,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.zip.ZipFile;
public class ZUGFeRDExporterFromA3Factory implements IExporterFactory { public class ZUGFeRDExporterFromA3Factory implements IExporterFactory {
protected boolean ignorePDFAErrors = false; protected boolean ignorePDFAErrors = false;
@@ -41,6 +40,7 @@ public class ZUGFeRDExporterFromA3Factory implements IExporterFactory {
protected PDMetadata metadata = null; protected PDMetadata metadata = null;
protected PDFAIdentificationSchema pdfaid = null; protected PDFAIdentificationSchema pdfaid = null;
protected XMPMetadata xmp = null; protected XMPMetadata xmp = null;
protected int ZFVersion=2;
/** /**
* Makes A PDF/A3a-compliant document from a PDF-A1 compliant document (on the * Makes A PDF/A3a-compliant document from a PDF-A1 compliant document (on the
* metadata level, this will not e.g. convert graphics to JPG-2000) * metadata level, this will not e.g. convert graphics to JPG-2000)
@@ -56,6 +56,10 @@ public class ZUGFeRDExporterFromA3Factory implements IExporterFactory {
} }
public void setZUGFeRDversion(int version) {
ZFVersion=version;
}
public void prepareDocument(PDDocument doc) throws IOException { public void prepareDocument(PDDocument doc) throws IOException {
String fullProducer = producer + " (via mustangproject.org " + org.mustangproject.ZUGFeRD.Version.VERSION + ")"; String fullProducer = producer + " (via mustangproject.org " + org.mustangproject.ZUGFeRD.Version.VERSION + ")";
@@ -102,7 +106,7 @@ public class ZUGFeRDExporterFromA3Factory implements IExporterFactory {
PDDocument doc = PDDocument.load(pdfBinary); PDDocument doc = PDDocument.load(pdfBinary);
prepareDocument(doc); prepareDocument(doc);
zugFeRDExporter = new ZUGFeRDExporter(doc); zugFeRDExporter = new ZUGFeRDExporter(doc);
zugFeRDExporter.setZUGFeRDVersion(ZFVersion);
return zugFeRDExporter; return zugFeRDExporter;
} }
@@ -164,7 +168,7 @@ public class ZUGFeRDExporterFromA3Factory implements IExporterFactory {
public void addXMP(XMPMetadata metadata) { public void addXMP(XMPMetadata metadata) {
if (attachZugferdHeaders) { if (attachZugferdHeaders) {
XMPSchemaZugferd zf = new XMPSchemaZugferd(metadata, zugferdConformanceLevel); XMPSchemaZugferd zf = new XMPSchemaZugferd(metadata, zugferdConformanceLevel, ZUGFeRDExporter.getNamespaceForVersion(ZFVersion), ZUGFeRDExporter.getPrefixForVersion(ZFVersion), ZUGFeRDExporter.getFilenameForVersion(ZFVersion) );
metadata.addSchema(zf); metadata.addSchema(zf);
} }

View File

@@ -89,7 +89,7 @@ public class ZUGFeRDImporter {
* currently (in the release candidate of version 1) only one * currently (in the release candidate of version 1) only one
* attached file with the name ZUGFeRD-invoice.xml is allowed * attached file with the name ZUGFeRD-invoice.xml is allowed
* */ * */
if (filename.equals("ZUGFeRD-invoice.xml")) { //$NON-NLS-1$ if ((filename.equals("ZUGFeRD-invoice.xml")||filename.equals("factur-x.xml"))) { //$NON-NLS-1$
containsMeta = true; containsMeta = true;
PDComplexFileSpecification fileSpec = efMap.get(filename); PDComplexFileSpecification fileSpec = efMap.get(filename);
@@ -284,6 +284,11 @@ public class ZUGFeRDImporter {
} }
ndList = document.getElementsByTagNameNS("*","SpecifiedTradePaymentTerms"); //$NON-NLS-1$ ndList = document.getElementsByTagNameNS("*","SpecifiedTradePaymentTerms"); //$NON-NLS-1$
if (ndList.getLength()==0) {
// try ZF1, it can not harm
ndList = document.getElementsByTagNameNS("*","SpecifiedCITradePaymentTerms"); //$NON-NLS-1$
}
for (int bookingIndex = 0; bookingIndex < ndList for (int bookingIndex = 0; bookingIndex < ndList
.getLength(); bookingIndex++) { .getLength(); bookingIndex++) {

View File

@@ -410,7 +410,7 @@ public class MustangReaderWriterEdgeTest extends TestCase implements IZUGFeRDExp
.setCreator(System.getProperty("user.name")) .setCreator(System.getProperty("user.name"))
.ignorePDFAErrors() .ignorePDFAErrors()
.load(SOURCE_PDF)) { .load(SOURCE_PDF)) {
ze.setVersion(1); ze.setZUGFeRDVersion(1);
ze.PDFattachZugferdFile(this); ze.PDFattachZugferdFile(this);
ze.export(TARGET_PDF); ze.export(TARGET_PDF);
} }