Class Converter


  • public class Converter
    extends NativeObject

    The class to convert PDF documents to PDF/A

    • Constructor Detail

      • Converter

        public Converter()
    • Method Detail

      • addInvoiceXml

        public void addInvoiceXml​(InvoiceType invoiceType,
                                  Stream invoice)

        Prepares the invoice XML file (ZUGFeRD or Factur-X) for embedding.

        Note: This requires the compliance to be set to PDF/A-3.
        Parameters:
        invoiceType - The type of invoice.
        invoice - The XML invoice stream.
        Throws:
        java.lang.IllegalArgumentException - The invoice stream could not be opened for reading.
        java.lang.IllegalArgumentException - if invoiceType is null
        java.lang.IllegalArgumentException - if invoice is null
      • addInvoiceXml

        public void addInvoiceXml​(InvoiceType invoiceType,
                                  Stream invoice,
                                  AFRelationship afRelationship)

        Prepares the invoice XML file (ZUGFeRD or Factur-X) for embedding.

        Note: This requires the compliance to be set to PDF/A-3.
        Parameters:
        invoiceType - The type of invoice.
        invoice - The XML invoice stream.
        afRelationship - If no value is provided, a sensible default value is chosen based on the invoice type and version.
        Throws:
        java.lang.IllegalArgumentException - The invoice stream could not be opened for reading.
        java.lang.IllegalArgumentException - if invoiceType is null
        java.lang.IllegalArgumentException - if invoice is null
      • addAssociatedFile

        public void addAssociatedFile​(Stream embeddedFile,
                                      java.lang.String name)
                               throws java.io.IOException

        Prepares the associated file for embedding.

        Add a file to the document’s embedded files. For PDF/A-3, the embedded file is associated with an object of the document, i.e. it is an associated file. The file is embedded as-is. Embedding files is not allowed for PDF/A-1 and restricted to PDF/A conforming files for PDF/A-2.
        Parameters:
        embeddedFile - The stream of the embedded file.
        name - The name used for the embedded file. This name is presented to the user when viewing the list of embedded files.
        Throws:
        java.lang.IllegalArgumentException - The associated file stream could not be opened for reading.
        java.lang.IllegalArgumentException - The associate argument is invalid.
        java.io.IOException - Error reading from embeddedFile.
        java.lang.IllegalArgumentException - if embeddedFile is null
        java.lang.IllegalArgumentException - if name is null
      • addAssociatedFile

        public void addAssociatedFile​(Stream embeddedFile,
                                      java.lang.String name,
                                      java.lang.Integer associate)
                               throws java.io.IOException

        Prepares the associated file for embedding.

        Add a file to the document’s embedded files. For PDF/A-3, the embedded file is associated with an object of the document, i.e. it is an associated file. The file is embedded as-is. Embedding files is not allowed for PDF/A-1 and restricted to PDF/A conforming files for PDF/A-2.
        Parameters:
        embeddedFile - The stream of the embedded file.
        name - The name used for the embedded file. This name is presented to the user when viewing the list of embedded files.
        associate - The object to associate the embedded file with, -1 for none, 0 for document, number greater than 0 for respective page. If null, the default value is 0 for PDF/A-3 and -1 otherwise.
        Throws:
        java.lang.IllegalArgumentException - The associated file stream could not be opened for reading.
        java.lang.IllegalArgumentException - The associate argument is invalid.
        java.io.IOException - Error reading from embeddedFile.
        java.lang.IllegalArgumentException - if embeddedFile is null
        java.lang.IllegalArgumentException - if name is null
      • addAssociatedFile

        public void addAssociatedFile​(Stream embeddedFile,
                                      java.lang.String name,
                                      java.lang.Integer associate,
                                      AFRelationship afRelationship)
                               throws java.io.IOException

        Prepares the associated file for embedding.

        Add a file to the document’s embedded files. For PDF/A-3, the embedded file is associated with an object of the document, i.e. it is an associated file. The file is embedded as-is. Embedding files is not allowed for PDF/A-1 and restricted to PDF/A conforming files for PDF/A-2.
        Parameters:
        embeddedFile - The stream of the embedded file.
        name - The name used for the embedded file. This name is presented to the user when viewing the list of embedded files.
        associate - The object to associate the embedded file with, -1 for none, 0 for document, number greater than 0 for respective page. If null, the default value is 0 for PDF/A-3 and -1 otherwise.
        afRelationship - The relationship of the embedded file to the object associate. (Ignored, if associate is -1.) If null, the default value is AFRelationship.UNSPECIFIED.
        Throws:
        java.lang.IllegalArgumentException - The associated file stream could not be opened for reading.
        java.lang.IllegalArgumentException - The associate argument is invalid.
        java.io.IOException - Error reading from embeddedFile.
        java.lang.IllegalArgumentException - if embeddedFile is null
        java.lang.IllegalArgumentException - if name is null
      • addAssociatedFile

        public void addAssociatedFile​(Stream embeddedFile,
                                      java.lang.String name,
                                      java.lang.Integer associate,
                                      AFRelationship afRelationship,
                                      java.lang.String mimeType)
                               throws java.io.IOException

        Prepares the associated file for embedding.

        Add a file to the document’s embedded files. For PDF/A-3, the embedded file is associated with an object of the document, i.e. it is an associated file. The file is embedded as-is. Embedding files is not allowed for PDF/A-1 and restricted to PDF/A conforming files for PDF/A-2.
        Parameters:
        embeddedFile - The stream of the embedded file.
        name - The name used for the embedded file. This name is presented to the user when viewing the list of embedded files.
        associate - The object to associate the embedded file with, -1 for none, 0 for document, number greater than 0 for respective page. If null, the default value is 0 for PDF/A-3 and -1 otherwise.
        afRelationship - The relationship of the embedded file to the object associate. (Ignored, if associate is -1.) If null, the default value is AFRelationship.UNSPECIFIED.
        mimeType - MIME ­Type of the embedded file. Common values other than the default are "application/pdf", "application/xml" or "application/msword". If null, the default value is "application/octet-stream".
        Throws:
        java.lang.IllegalArgumentException - The associated file stream could not be opened for reading.
        java.lang.IllegalArgumentException - The associate argument is invalid.
        java.io.IOException - Error reading from embeddedFile.
        java.lang.IllegalArgumentException - if embeddedFile is null
        java.lang.IllegalArgumentException - if name is null
      • addAssociatedFile

        public void addAssociatedFile​(Stream embeddedFile,
                                      java.lang.String name,
                                      java.lang.Integer associate,
                                      AFRelationship afRelationship,
                                      java.lang.String mimeType,
                                      java.lang.String description)
                               throws java.io.IOException

        Prepares the associated file for embedding.

        Add a file to the document’s embedded files. For PDF/A-3, the embedded file is associated with an object of the document, i.e. it is an associated file. The file is embedded as-is. Embedding files is not allowed for PDF/A-1 and restricted to PDF/A conforming files for PDF/A-2.
        Parameters:
        embeddedFile - The stream of the embedded file.
        name - The name used for the embedded file. This name is presented to the user when viewing the list of embedded files.
        associate - The object to associate the embedded file with, -1 for none, 0 for document, number greater than 0 for respective page. If null, the default value is 0 for PDF/A-3 and -1 otherwise.
        afRelationship - The relationship of the embedded file to the object associate. (Ignored, if associate is -1.) If null, the default value is AFRelationship.UNSPECIFIED.
        mimeType - MIME ­Type of the embedded file. Common values other than the default are "application/pdf", "application/xml" or "application/msword". If null, the default value is "application/octet-stream".
        description - A description of the embedded file. This is presented to the user when viewing the list of embedded files. If null, the default value is "".
        Throws:
        java.lang.IllegalArgumentException - The associated file stream could not be opened for reading.
        java.lang.IllegalArgumentException - The associate argument is invalid.
        java.io.IOException - Error reading from embeddedFile.
        java.lang.IllegalArgumentException - if embeddedFile is null
        java.lang.IllegalArgumentException - if name is null
      • addAssociatedFile

        public void addAssociatedFile​(Stream embeddedFile,
                                      java.lang.String name,
                                      java.lang.Integer associate,
                                      AFRelationship afRelationship,
                                      java.lang.String mimeType,
                                      java.lang.String description,
                                      java.time.OffsetDateTime modificationDate)
                               throws java.io.IOException

        Prepares the associated file for embedding.

        Add a file to the document’s embedded files. For PDF/A-3, the embedded file is associated with an object of the document, i.e. it is an associated file. The file is embedded as-is. Embedding files is not allowed for PDF/A-1 and restricted to PDF/A conforming files for PDF/A-2.
        Parameters:
        embeddedFile - The stream of the embedded file.
        name - The name used for the embedded file. This name is presented to the user when viewing the list of embedded files.
        associate - The object to associate the embedded file with, -1 for none, 0 for document, number greater than 0 for respective page. If null, the default value is 0 for PDF/A-3 and -1 otherwise.
        afRelationship - The relationship of the embedded file to the object associate. (Ignored, if associate is -1.) If null, the default value is AFRelationship.UNSPECIFIED.
        mimeType - MIME ­Type of the embedded file. Common values other than the default are "application/pdf", "application/xml" or "application/msword". If null, the default value is "application/octet-stream".
        description - A description of the embedded file. This is presented to the user when viewing the list of embedded files. If null, the default value is "".
        modificationDate - The modify date of the file. If null, the default value is modification date of the file on the file system or current time, if not available.
        Throws:
        java.lang.IllegalArgumentException - The associated file stream could not be opened for reading.
        java.lang.IllegalArgumentException - The associate argument is invalid.
        java.io.IOException - Error reading from embeddedFile.
        java.lang.IllegalArgumentException - if embeddedFile is null
        java.lang.IllegalArgumentException - if name is null
      • convert

        public Document convert​(AnalysisResult analysis,
                                Document document,
                                Stream outStream)
                         throws java.io.IOException,
                                NotFoundException,
                                GenericException,
                                LicenseException,
                                CorruptException,
                                ConformanceException,
                                UnsupportedFeatureException,
                                ProcessingException

        Convert a document to PDF/A.

        Note that it is highly recommended to use Converter.ConversionEventListener to detect critical conversion events.
        Parameters:
        analysis - The result of the document's analysis using pdftools.pdfa.validation.Validator.analyze.
        document - The document to convert
        outStream - The stream where the converted document is written
        Returns:
        The result of the conversion
        Throws:
        LicenseException - The license check has failed.
        java.lang.IllegalArgumentException - The outOptions argument is invalid.
        java.lang.IllegalArgumentException - The output stream could not be opened for writing.
        java.lang.IllegalStateException - The document has already been closed.
        java.lang.IllegalArgumentException - The analysis has already been closed, e.g. due to a previous conversion.
        java.lang.IllegalArgumentException - The PDF/A version of the analysis and the conversion options do not match.
        java.lang.IllegalArgumentException - The analysis is not the analysis result of document.
        java.io.IOException - Error reading from or writing to the outStream.
        ConformanceException - The conformance required by options cannot be achieved.
        • PDF/A level U: All text of the input document must be extractable.
        • PDF/A level A: In addition to the requirements of level U, the input document must be tagged.
        ConformanceException - The PDF/A version of the conformances of analysis and options differ. The same PDF/A version must be used for the analysis and conversion.
        java.lang.IllegalArgumentException - The outOptions specifies document encryption, which is not allowed in PDF/A documents.
        GenericException - The document cannot be converted to PDF/A.
        CorruptException - The analysis has been stopped.
        ProcessingException - Failed to add the invoice file. Possible reasons include an invalid XML format, or that the invoice type conflicts with the content of the XML file.
        UnsupportedFeatureException - The document is not a PDF, but an XFA document. See pdftools.pdf.Document.getXfa for more information on how to detect and handle XFA documents.
        NotFoundException - A required font is missing from the installed font directories.
        java.lang.IllegalStateException - Invalid associate value for an embedded file.
        java.lang.IllegalArgumentException - if analysis is null
        java.lang.IllegalArgumentException - if document is null
        java.lang.IllegalArgumentException - if outStream is null
      • convert

        public Document convert​(AnalysisResult analysis,
                                Document document,
                                Stream outStream,
                                ConversionOptions options)
                         throws java.io.IOException,
                                NotFoundException,
                                GenericException,
                                LicenseException,
                                CorruptException,
                                ConformanceException,
                                UnsupportedFeatureException,
                                ProcessingException

        Convert a document to PDF/A.

        Note that it is highly recommended to use Converter.ConversionEventListener to detect critical conversion events.
        Parameters:
        analysis - The result of the document's analysis using pdftools.pdfa.validation.Validator.analyze.
        document - The document to convert
        outStream - The stream where the converted document is written
        options - The conversion options
        Returns:
        The result of the conversion
        Throws:
        LicenseException - The license check has failed.
        java.lang.IllegalArgumentException - The outOptions argument is invalid.
        java.lang.IllegalArgumentException - The output stream could not be opened for writing.
        java.lang.IllegalStateException - The document has already been closed.
        java.lang.IllegalArgumentException - The analysis has already been closed, e.g. due to a previous conversion.
        java.lang.IllegalArgumentException - The PDF/A version of the analysis and the conversion options do not match.
        java.lang.IllegalArgumentException - The analysis is not the analysis result of document.
        java.io.IOException - Error reading from or writing to the outStream.
        ConformanceException - The conformance required by options cannot be achieved.
        • PDF/A level U: All text of the input document must be extractable.
        • PDF/A level A: In addition to the requirements of level U, the input document must be tagged.
        ConformanceException - The PDF/A version of the conformances of analysis and options differ. The same PDF/A version must be used for the analysis and conversion.
        java.lang.IllegalArgumentException - The outOptions specifies document encryption, which is not allowed in PDF/A documents.
        GenericException - The document cannot be converted to PDF/A.
        CorruptException - The analysis has been stopped.
        ProcessingException - Failed to add the invoice file. Possible reasons include an invalid XML format, or that the invoice type conflicts with the content of the XML file.
        UnsupportedFeatureException - The document is not a PDF, but an XFA document. See pdftools.pdf.Document.getXfa for more information on how to detect and handle XFA documents.
        NotFoundException - A required font is missing from the installed font directories.
        java.lang.IllegalStateException - Invalid associate value for an embedded file.
        java.lang.IllegalArgumentException - if analysis is null
        java.lang.IllegalArgumentException - if document is null
        java.lang.IllegalArgumentException - if outStream is null
      • convert

        public Document convert​(AnalysisResult analysis,
                                Document document,
                                Stream outStream,
                                ConversionOptions options,
                                OutputOptions outOptions)
                         throws java.io.IOException,
                                NotFoundException,
                                GenericException,
                                LicenseException,
                                CorruptException,
                                ConformanceException,
                                UnsupportedFeatureException,
                                ProcessingException

        Convert a document to PDF/A.

        Note that it is highly recommended to use Converter.ConversionEventListener to detect critical conversion events.
        Parameters:
        analysis - The result of the document's analysis using pdftools.pdfa.validation.Validator.analyze.
        document - The document to convert
        outStream - The stream where the converted document is written
        options - The conversion options
        outOptions - The output options object
        Returns:
        The result of the conversion
        Throws:
        LicenseException - The license check has failed.
        java.lang.IllegalArgumentException - The outOptions argument is invalid.
        java.lang.IllegalArgumentException - The output stream could not be opened for writing.
        java.lang.IllegalStateException - The document has already been closed.
        java.lang.IllegalArgumentException - The analysis has already been closed, e.g. due to a previous conversion.
        java.lang.IllegalArgumentException - The PDF/A version of the analysis and the conversion options do not match.
        java.lang.IllegalArgumentException - The analysis is not the analysis result of document.
        java.io.IOException - Error reading from or writing to the outStream.
        ConformanceException - The conformance required by options cannot be achieved.
        • PDF/A level U: All text of the input document must be extractable.
        • PDF/A level A: In addition to the requirements of level U, the input document must be tagged.
        ConformanceException - The PDF/A version of the conformances of analysis and options differ. The same PDF/A version must be used for the analysis and conversion.
        java.lang.IllegalArgumentException - The outOptions specifies document encryption, which is not allowed in PDF/A documents.
        GenericException - The document cannot be converted to PDF/A.
        CorruptException - The analysis has been stopped.
        ProcessingException - Failed to add the invoice file. Possible reasons include an invalid XML format, or that the invoice type conflicts with the content of the XML file.
        UnsupportedFeatureException - The document is not a PDF, but an XFA document. See pdftools.pdf.Document.getXfa for more information on how to detect and handle XFA documents.
        NotFoundException - A required font is missing from the installed font directories.
        java.lang.IllegalStateException - Invalid associate value for an embedded file.
        java.lang.IllegalArgumentException - if analysis is null
        java.lang.IllegalArgumentException - if document is null
        java.lang.IllegalArgumentException - if outStream is null