Class DXExporterFromA3

    • Field Detail

      • 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.
      • 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.
      • 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
      • despatchAdviceDocumentType

        protected java.lang.String despatchAdviceDocumentType
        OrderX document type. As of version 1.0 it may be ORDER, ORDER_RESPONSE, or ORDER_CHANGE
    • Constructor Detail

      • DXExporterFromA3

        public DXExporterFromA3()
    • Method Detail

      • load

        public DXExporterFromA3 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
        Overrides:
        load in class ZUGFeRDExporterFromA3
        Parameters:
        pdfFilename - filename of an PDF/A1 compliant document
        Returns:
        the generated exporter
        Throws:
        java.io.IOException - if anything is wrong with filename
      • load

        public DXExporterFromA3 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
        Overrides:
        load in class ZUGFeRDExporterFromA3
        Parameters:
        pdfBinary - binary of a PDF/A1 compliant document
        Returns:
        the generated exporter
        Throws:
        java.io.IOException - (should not happen at all)
      • 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 ZUGFeRDExporterFromA3
        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
        Overrides:
        close in class ZUGFeRDExporterFromA3
        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 ZUGFeRDExporterFromA3
        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.
        Overrides:
        PDFAttachGenericFile in class ZUGFeRDExporterFromA3
        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.
        Overrides:
        PDFAttachGenericFile in class ZUGFeRDExporterFromA3
        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 DXExporterFromA3 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
        Overrides:
        setXML in class ZUGFeRDExporterFromA3
        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 DXExporterFromA3 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
        Overrides:
        load in class ZUGFeRDExporterFromA3
        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
      • setConformanceLevel

        public DXExporterFromA3 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
        Overrides:
        setConformanceLevel in class ZUGFeRDExporterFromA3
      • setDocumentType

        public DXExporterFromA3 setDocumentType​(java.lang.String DocumentType)
        Sets the property for DocumentType.
        Parameters:
        DocumentType - String, usually DESPATCHADVICE
        Returns:
        this exporter
      • 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
        Overrides:
        addXMP in class ZUGFeRDExporterFromA3
        Parameters:
        metadata - the PDFbox XMPMetadata object
      • 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 ZUGFeRDExporterFromA3
        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
      • getXmpMetadata

        protected org.apache.xmpbox.XMPMetadata getXmpMetadata()
                                                        throws java.io.IOException
        Reads the XMPMetadata from the PDDocument, if it exists. Otherwise creates XMPMetadata.
        Overrides:
        getXmpMetadata in class ZUGFeRDExporterFromA3
        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
        Overrides:
        serializeXmpMetadata in class ZUGFeRDExporterFromA3
        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.
        Overrides:
        writeAdobePDFSchema in class ZUGFeRDExporterFromA3
        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.
        Overrides:
        getAdobePDFSchema in class ZUGFeRDExporterFromA3
        Parameters:
        xmp - the metadata to attach to
        Returns:
        the pdf schema
      • getXmpBasicSchema

        protected org.apache.xmpbox.schema.XMPBasicSchema getXmpBasicSchema​(org.apache.xmpbox.XMPMetadata xmp)
        Overrides:
        getXmpBasicSchema in class ZUGFeRDExporterFromA3
      • addSRGBOutputIntend

        protected void addSRGBOutputIntend()
                                    throws java.io.IOException
        Adds an OutputIntent and the sRGB color profile if no OutputIntent exist
        Overrides:
        addSRGBOutputIntend in class ZUGFeRDExporterFromA3
        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.
        Overrides:
        setMarked in class ZUGFeRDExporterFromA3