Class ZUGFeRDExporterFromA3

    • Field Detail

      • ignorePDFAErrors

        protected boolean ignorePDFAErrors
      • 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
    • Constructor Detail

      • ZUGFeRDExporterFromA3

        public ZUGFeRDExporterFromA3()
    • Method Detail

      • 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:
        load in interface IZUGFeRDExporter
        Parameters:
        pdfFilename - filename of an PDF/A1 compliant document
        Returns:
        the generated exporter
        Throws:
        java.io.IOException - if anything is wrong with filename
      • 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:
        getNamespaceForVersion in interface IZUGFeRDExporter
        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:
        getPrefixForVersion in interface IZUGFeRDExporter
        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 version
        profile - 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 anyway
        Factur-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
      • 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:
        load in interface IZUGFeRDExporter
        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​(java.lang.String filename,
                               byte[] data,
                               java.lang.String mimetype,
                               java.lang.String relation)
        Specified by:
        attachFile in interface IZUGFeRDExporter
      • export

        public void export​(java.lang.String ZUGFeRDfilename)
                    throws java.io.IOException
        Perform the final export to a now ZUGFeRD-enriched PDF file
        Specified by:
        export in interface IExporter
        Overrides:
        export in class XRExporter
        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:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException
      • export

        public void export​(java.io.OutputStream output)
                    throws java.io.IOException
        Perform the final export to a now ZUGFeRD-enriched PDF file as OutputStream
        Specified by:
        export in interface IExporter
        Overrides:
        export in class XRExporter
        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.IOException
        Embeds 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 PDF
        relationship - how the file relates to the content, e.g. "Alternative"
        description - Human-readable description of the file content
        subType - type of the data e.g. could be "text/xml" - mime like
        data - 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.IOException
        Embeds 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 PDF
        relationship - how the file relates to the content, e.g. "Alternative"
        description - Human-readable description of the file content
        subType - type of the data e.g. could be "text/xml" - mime like
        data - 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:
        setXML in interface IZUGFeRDExporter
        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:
        load in interface IZUGFeRDExporter
        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:
        ensurePDFIsValid in interface IZUGFeRDExporter
        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:
        setConformanceLevel in interface IZUGFeRDExporter
      • 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:
        setTransaction in interface IExporter
        Overrides:
        setTransaction in class XRExporter
        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 via setZUGFeRDXMLData(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.IOException
        Reads 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.IOException
        Adds 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
      • setXMLProvider

        protected void setXMLProvider​(IXMLProvider p)