Package org.mustangproject.ZUGFeRD
Class ZUGFeRDExporterFromA3
- java.lang.Object
-
- org.mustangproject.ZUGFeRD.XRExporter
-
- org.mustangproject.ZUGFeRD.ZUGFeRDExporterFromA3
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,IExporter,IZUGFeRDExporter
- Direct Known Subclasses:
DXExporterFromA3,OXExporterFromA3,ZUGFeRDExporterFromA1
public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporter
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.StringauthorDeprecated.author is never set yetprotected PDFAConformanceLevelconformanceLevelprotected java.lang.StringcreatorAuthor/Creator attribute for PDFprotected java.lang.StringcreatorToolCreatorToolstatic intDefaultZUGFeRDVersionprotected org.apache.pdfbox.pdmodel.PDDocumentdocprotected booleandocumentPreparedprotected java.util.ArrayList<FileAttachment>fileAttachmentsprotected booleanignorePDFAErrorsprotected org.apache.pdfbox.pdmodel.common.PDMetadatametadataData (XML invoice) to be added to the ZUGFeRD PDF.protected booleanoverwriteThis flag controls whether or not the metadata is overwritten, or kind of merged.protected java.lang.StringproducerProducer attribute for PDFprotected java.lang.StringsubjectDeprecated.subject is never set yetprotected java.lang.StringtitleDeprecated.title is never set yetprotected org.apache.xmpbox.XMPMetadataxmpprotected java.lang.StringXRechnungVersionprotected intZFVersion
-
Constructor Summary
Constructors Constructor Description ZUGFeRDExporterFromA3()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description ZUGFeRDExporterFromA3addAdditionalFile(java.lang.String name, byte[] content)protected voidaddSRGBOutputIntend()Adds an OutputIntent and the sRGB color profile if no OutputIntent existprotected voidaddStructureTreeRoot()Adds a StructureTreeRoot element to the PDF if it doesn't already exist.protected voidaddXMP(org.apache.xmpbox.XMPMetadata metadata)This will add both the RDF-indication which embedded file is Zugferd and the neccessary PDF/A schema extension description to be able to add this information to RDFvoidattachFile(java.lang.String filename, byte[] data, java.lang.String mimetype, java.lang.String relation)voidattachFile(FileAttachment file)voidclose()ZUGFeRDExporterFromA3disableAutoClose(boolean disableAutoClose)IZUGFeRDExporterdisableFacturX()Generate ZF2.0/2.1 files with filename zugferd-invoice.xml instead of factur-x.xmlbooleanensurePDFIsValid(jakarta.activation.DataSource dataSource)voidexport(java.io.OutputStream output)Perform the final export to a now ZUGFeRD-enriched PDF file as OutputStreamvoidexport(java.lang.String ZUGFeRDfilename)Perform the final export to a now ZUGFeRD-enriched PDF fileprotected org.apache.xmpbox.schema.AdobePDFSchemagetAdobePDFSchema(org.apache.xmpbox.XMPMetadata xmp)Returns the AdobePDFSchema from the XMPMetadata if it exists.protected org.apache.xmpbox.schema.DublinCoreSchemagetDublinCoreSchema(org.apache.xmpbox.XMPMetadata xmp)java.lang.StringgetFilenameForVersion(int ver, Profile profile)internal helper: return the name of the file attachment for the given zf/fx versionjava.lang.StringgetNamespaceForVersion(int ver)internal helper function: get namespace for given zugferd or factur-x versionprotected org.apache.xmpbox.schema.PDFAIdentificationSchemagetPDFAIdentificationSchema(org.apache.xmpbox.XMPMetadata xmp)java.lang.StringgetPrefixForVersion(int ver)internal helper: returns the namespace prefix for the given zf/fx version numberIXMLProvidergetProvider()protected org.apache.xmpbox.schema.XMPBasicSchemagetXmpBasicSchema(org.apache.xmpbox.XMPMetadata xmp)protected org.apache.xmpbox.XMPMetadatagetXmpMetadata()Reads the XMPMetadata from the PDDocument, if it exists.ZUGFeRDExporterFromA3ignorePDFAErrors()booleanisAutoCloseDisabled()ZUGFeRDExporterFromA3load(byte[] pdfBinary)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)ZUGFeRDExporterFromA3load(java.io.InputStream pdfSource)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)ZUGFeRDExporterFromA3load(java.lang.String pdfFilename)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)voidPDFAttachGenericFile(java.lang.String filename, java.lang.String relationship, java.lang.String description, java.lang.String subType, byte[] data)Embeds an external file (generic - any type allowed) in the PDF.voidPDFAttachGenericFile(org.apache.pdfbox.pdmodel.PDDocument doc, java.lang.String filename, java.lang.String relationship, java.lang.String description, java.lang.String subType, byte[] data)Embeds an external file (generic - any type allowed) in the PDF.IExporterprepare()protected voidprepareDocument()protected byte[]serializeXmpMetadata(org.apache.xmpbox.XMPMetadata xmpMetadata)protected ZUGFeRDExporterFromA3setAttachZUGFeRDHeaders(boolean attachHeaders)ZUGFeRDExporterFromA3setConformanceLevel(PDFAConformanceLevel newLevel)All files are PDF/A-3, setConformance refers to the level conformance.ZUGFeRDExporterFromA3setCreator(java.lang.String creator)ZUGFeRDExporterFromA3setCreatorTool(java.lang.String creatorTool)ZUGFeRDExporterFromA3setFacturX()Deprecated.It's now the default anywayprotected voidsetMarked()Adds a MarkInfo element to the PDF if it doesn't already exist and sets it as marked.ZUGFeRDExporterFromA3setProducer(java.lang.String producer)ZUGFeRDExporterFromA3setProfile(java.lang.String profilename)ZUGFeRDExporterFromA3setProfile(Profile p)IExportersetTransaction(IExportableTransaction trans)Embeds the Zugferd XML structure in a file named ZUGFeRD-invoice.xml.ZUGFeRDExporterFromA3setXML(byte[] zugferdData)Sets the ZUGFeRD XML data to be attached as a single byte array.protected voidsetXMLProvider(IXMLProvider p)voidsetXRechnungSpecificVersion(java.lang.String XRechnungVersion)Sets a specific XRechnung version from outside.ZUGFeRDExporterFromA3setZUGFeRDVersion(int version)ZUGFeRDExporterFromA3setZUGFeRDVersion(EStandard est, int version)protected voidwriteAdobePDFSchema(org.apache.xmpbox.XMPMetadata xmp)Sets the producer if the overwrite flag is set or the producer is not already set.protected voidwriteDocumentInformation()protected voidwriteDublinCoreSchema(org.apache.xmpbox.XMPMetadata xmp)protected voidwritePDFAIdentificationSchema(org.apache.xmpbox.XMPMetadata xmp)protected voidwriteXMLBasicSchema(org.apache.xmpbox.XMPMetadata xmp)
-
-
-
Field Detail
-
DefaultZUGFeRDVersion
public static final int DefaultZUGFeRDVersion
- See Also:
- Constant Field Values
-
ignorePDFAErrors
protected boolean ignorePDFAErrors
-
conformanceLevel
protected PDFAConformanceLevel conformanceLevel
-
fileAttachments
protected java.util.ArrayList<FileAttachment> fileAttachments
-
overwrite
protected boolean overwrite
This flag controls whether or not the metadata is overwritten, or kind of merged. The merging probably needs to be overhauled, but for my purpose it was good enough.
-
documentPrepared
protected boolean documentPrepared
-
metadata
protected org.apache.pdfbox.pdmodel.common.PDMetadata metadata
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.
-
xmp
protected org.apache.xmpbox.XMPMetadata xmp
-
producer
protected java.lang.String producer
Producer attribute for PDF
-
creator
protected java.lang.String creator
Author/Creator attribute for PDF
-
creatorTool
protected java.lang.String creatorTool
CreatorTool
-
author
@Deprecated protected java.lang.String author
Deprecated.author is never set yet
-
title
@Deprecated protected java.lang.String title
Deprecated.title is never set yet
-
subject
@Deprecated protected java.lang.String subject
Deprecated.subject is never set yet
-
doc
protected org.apache.pdfbox.pdmodel.PDDocument doc
-
ZFVersion
protected int ZFVersion
-
XRechnungVersion
protected java.lang.String XRechnungVersion
-
-
Method Detail
-
ignorePDFAErrors
public ZUGFeRDExporterFromA3 ignorePDFAErrors()
-
load
public ZUGFeRDExporterFromA3 load(java.lang.String pdfFilename) throws java.io.IOException
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)- Specified by:
loadin interfaceIZUGFeRDExporter- Parameters:
pdfFilename- filename of an PDF/A1 compliant document- Returns:
- the generated exporter
- Throws:
java.io.IOException- if anything is wrong with filename
-
getProvider
public IXMLProvider getProvider()
- Specified by:
getProviderin interfaceIZUGFeRDExporter
-
setProfile
public ZUGFeRDExporterFromA3 setProfile(Profile p)
- Specified by:
setProfilein interfaceIZUGFeRDExporter
-
setProfile
public ZUGFeRDExporterFromA3 setProfile(java.lang.String profilename)
-
addAdditionalFile
public ZUGFeRDExporterFromA3 addAdditionalFile(java.lang.String name, byte[] content)
-
getNamespaceForVersion
public java.lang.String getNamespaceForVersion(int ver)
internal helper function: get namespace for given zugferd or factur-x version- Specified by:
getNamespaceForVersionin interfaceIZUGFeRDExporter- Parameters:
ver- the ZUGFeRD version- Returns:
- the URN of the namespace
-
getPrefixForVersion
public java.lang.String getPrefixForVersion(int ver)
internal helper: returns the namespace prefix for the given zf/fx version number- Specified by:
getPrefixForVersionin interfaceIZUGFeRDExporter- Parameters:
ver- the zf/fx version- Returns:
- the namespace prefix as string, without colon
-
getFilenameForVersion
public java.lang.String getFilenameForVersion(int ver, Profile profile)internal helper: return the name of the file attachment for the given zf/fx version- Parameters:
ver- the zf/fx versionprofile- which profile to be used, e.g. Profiles.getByName("EN16931")- Returns:
- the filename of the file to be embedded
-
setFacturX
@Deprecated public ZUGFeRDExporterFromA3 setFacturX()
Deprecated.It's now the default anywayFactur-X is now set by default since ZF 2.1, you have to disable it if you dont wont it Generate ZF2.1 files with filename factur-x.xml- Returns:
- this (fluent setter)
-
setXRechnungSpecificVersion
public void setXRechnungSpecificVersion(java.lang.String XRechnungVersion)
Sets a specific XRechnung version from outside. This version needs to be present in the meta-data as well. The caller may wish to generate a specific version of XRechnung depending on the time period etc.- Parameters:
XRechnungVersion- the XRechnung version
-
disableFacturX
public IZUGFeRDExporter disableFacturX()
Generate ZF2.0/2.1 files with filename zugferd-invoice.xml instead of factur-x.xml- Specified by:
disableFacturXin interfaceIZUGFeRDExporter
-
load
public ZUGFeRDExporterFromA3 load(byte[] pdfBinary) throws java.io.IOException
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)- Specified by:
loadin interfaceIZUGFeRDExporter- Parameters:
pdfBinary- binary of a PDF/A1 compliant document- Returns:
- the generated exporter
- Throws:
java.io.IOException- (should not happen at all)
-
attachFile
public void attachFile(FileAttachment file)
- Specified by:
attachFilein interfaceIZUGFeRDExporter
-
attachFile
public void attachFile(java.lang.String filename, byte[] data, java.lang.String mimetype, java.lang.String relation)- Specified by:
attachFilein interfaceIZUGFeRDExporter
-
export
public void export(java.lang.String ZUGFeRDfilename) throws java.io.IOExceptionPerform the final export to a now ZUGFeRD-enriched PDF file- Specified by:
exportin interfaceIExporter- Overrides:
exportin classXRExporter- Parameters:
ZUGFeRDfilename- the pdf file name- Throws:
java.io.IOException- if anything is wrong in the target location
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
export
public void export(java.io.OutputStream output) throws java.io.IOExceptionPerform the final export to a now ZUGFeRD-enriched PDF file as OutputStream- Specified by:
exportin interfaceIExporter- Overrides:
exportin classXRExporter- Parameters:
output- the OutputStream- Throws:
java.io.IOException- if anything is wrong in the OutputStream
-
PDFAttachGenericFile
public void PDFAttachGenericFile(java.lang.String filename, java.lang.String relationship, java.lang.String description, java.lang.String subType, byte[] data) throws java.io.IOExceptionEmbeds an external file (generic - any type allowed) in the PDF. The embedding is done in the default PDF document.- Parameters:
filename- name of the file that will become attachment name in the PDFrelationship- how the file relates to the content, e.g. "Alternative"description- Human-readable description of the file contentsubType- type of the data e.g. could be "text/xml" - mime likedata- the binary data of the file/attachment- Throws:
java.io.IOException- if anything is wrong with filename
-
PDFAttachGenericFile
public void PDFAttachGenericFile(org.apache.pdfbox.pdmodel.PDDocument doc, java.lang.String filename, java.lang.String relationship, java.lang.String description, java.lang.String subType, byte[] data) throws java.io.IOExceptionEmbeds an external file (generic - any type allowed) in the PDF.- Parameters:
doc- PDDocument to attach the file to.filename- name of the file that will become attachment name in the PDFrelationship- how the file relates to the content, e.g. "Alternative"description- Human-readable description of the file contentsubType- type of the data e.g. could be "text/xml" - mime likedata- the binary data of the file/attachment- Throws:
java.io.IOException- if anything is wrong with filename
-
setXML
public ZUGFeRDExporterFromA3 setXML(byte[] zugferdData) throws java.io.IOException
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 external API or component.- Specified by:
setXMLin interfaceIZUGFeRDExporter- Parameters:
zugferdData- XML data to be set as a byte array (XML file in raw form).- Throws:
java.io.IOException- (should not happen)
-
load
public ZUGFeRDExporterFromA3 load(java.io.InputStream pdfSource) throws java.io.IOException
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)- Specified by:
loadin interfaceIZUGFeRDExporter- Parameters:
pdfSource- source to read a PDF/A1 compliant document from- Returns:
- the generated ZUGFeRDExporter
- Throws:
java.io.IOException- if anything is wrong with inputstream
-
ensurePDFIsValid
public boolean ensurePDFIsValid(jakarta.activation.DataSource dataSource) throws java.io.IOException- Specified by:
ensurePDFIsValidin interfaceIZUGFeRDExporter- Throws:
java.io.IOException
-
setConformanceLevel
public ZUGFeRDExporterFromA3 setConformanceLevel(PDFAConformanceLevel newLevel)
All files are PDF/A-3, setConformance refers to the level conformance.PDF/A-3 has three coformance levels, called "A", "U" and "B".
PDF/A-3-B where B means only visually preservable, U -standard for Mustang- means visually and unicode preservable and A means full compliance, i.e. visually, unicode and structurally preservable and tagged PDF, i.e. useful metainformation for blind people.
Feel free to pass "A" as new level if you know what you are doing :-)
- Specified by:
setConformanceLevelin interfaceIZUGFeRDExporter
-
setCreator
public ZUGFeRDExporterFromA3 setCreator(java.lang.String creator)
- Specified by:
setCreatorin interfaceIZUGFeRDExporter
-
setCreatorTool
public ZUGFeRDExporterFromA3 setCreatorTool(java.lang.String creatorTool)
-
setProducer
public ZUGFeRDExporterFromA3 setProducer(java.lang.String producer)
- Specified by:
setProducerin interfaceIZUGFeRDExporter
-
setAttachZUGFeRDHeaders
protected ZUGFeRDExporterFromA3 setAttachZUGFeRDHeaders(boolean attachHeaders)
-
addXMP
protected void addXMP(org.apache.xmpbox.XMPMetadata metadata)
This will add both the RDF-indication which embedded file is Zugferd and the neccessary PDF/A schema extension description to be able to add this information to RDF- Parameters:
metadata- the PDFbox XMPMetadata object
-
prepareDocument
protected void prepareDocument() throws java.io.IOException- Throws:
java.io.IOException
-
setTransaction
public IExporter setTransaction(IExportableTransaction trans) throws java.io.IOException
Embeds the Zugferd XML structure in a file named ZUGFeRD-invoice.xml.- Specified by:
setTransactionin interfaceIExporter- Overrides:
setTransactionin classXRExporter- Parameters:
trans- a IZUGFeRDExportableTransaction that provides the data-model to populate the XML. This parameter may be null, if so the XML data should hav ebeen set viasetZUGFeRDXMLData(byte[] zugferdData)- Throws:
java.io.IOException- if anything is wrong with already loaded PDF
-
prepare
public IExporter prepare() throws java.io.IOException
- Throws:
java.io.IOException
-
getXmpMetadata
protected org.apache.xmpbox.XMPMetadata getXmpMetadata() throws java.io.IOExceptionReads the XMPMetadata from the PDDocument, if it exists. Otherwise creates XMPMetadata.- Returns:
- the finished XMPMetadata object
- Throws:
java.io.IOException- when e.g. XmpParsingException
-
serializeXmpMetadata
protected byte[] serializeXmpMetadata(org.apache.xmpbox.XMPMetadata xmpMetadata) throws javax.xml.transform.TransformerException- Throws:
javax.xml.transform.TransformerException
-
writeAdobePDFSchema
protected void writeAdobePDFSchema(org.apache.xmpbox.XMPMetadata xmp)
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.- Parameters:
xmp- the metadata as XML
-
getAdobePDFSchema
protected org.apache.xmpbox.schema.AdobePDFSchema getAdobePDFSchema(org.apache.xmpbox.XMPMetadata xmp)
Returns the AdobePDFSchema from the XMPMetadata if it exists. If the overwrite flag is set or no AdobePDFSchema exists in the XMPMetadata, it is created, added and returned.- Parameters:
xmp- the metadata to attach to- Returns:
- the pdf schema
-
writePDFAIdentificationSchema
protected void writePDFAIdentificationSchema(org.apache.xmpbox.XMPMetadata xmp)
-
getPDFAIdentificationSchema
protected org.apache.xmpbox.schema.PDFAIdentificationSchema getPDFAIdentificationSchema(org.apache.xmpbox.XMPMetadata xmp)
-
writeDublinCoreSchema
protected void writeDublinCoreSchema(org.apache.xmpbox.XMPMetadata xmp)
-
getDublinCoreSchema
protected org.apache.xmpbox.schema.DublinCoreSchema getDublinCoreSchema(org.apache.xmpbox.XMPMetadata xmp)
-
writeXMLBasicSchema
protected void writeXMLBasicSchema(org.apache.xmpbox.XMPMetadata xmp)
-
getXmpBasicSchema
protected org.apache.xmpbox.schema.XMPBasicSchema getXmpBasicSchema(org.apache.xmpbox.XMPMetadata xmp)
-
writeDocumentInformation
protected void writeDocumentInformation()
-
addSRGBOutputIntend
protected void addSRGBOutputIntend() throws java.io.IOExceptionAdds an OutputIntent and the sRGB color profile if no OutputIntent exist- Throws:
java.io.IOException- if the ICC file cannot be read or attached to doc
-
setMarked
protected void setMarked()
Adds a MarkInfo element to the PDF if it doesn't already exist and sets it as marked.
-
addStructureTreeRoot
protected void addStructureTreeRoot()
Adds a StructureTreeRoot element to the PDF if it doesn't already exist.
-
isAutoCloseDisabled
public boolean isAutoCloseDisabled()
- Returns:
- if pdf file will be automatically closed after adding ZF
-
disableAutoClose
public ZUGFeRDExporterFromA3 disableAutoClose(boolean disableAutoClose)
- Specified by:
disableAutoClosein interfaceIZUGFeRDExporter- Parameters:
disableAutoClose- prevent PDF file from being closed after adding ZF
-
setXMLProvider
protected void setXMLProvider(IXMLProvider p)
-
setZUGFeRDVersion
public ZUGFeRDExporterFromA3 setZUGFeRDVersion(EStandard est, int version)
-
setZUGFeRDVersion
public ZUGFeRDExporterFromA3 setZUGFeRDVersion(int version)
- Specified by:
setZUGFeRDVersionin interfaceIZUGFeRDExporter
-
-