Class PDFMergerUtility


  • public class PDFMergerUtility
    extends java.lang.Object
    This class will take a list of pdf documents and merge them, saving the result in a new document.
    Author:
    Ben Litchfield
    • Constructor Detail

      • PDFMergerUtility

        public PDFMergerUtility()
        Instantiate a new PDFMergerUtility.
    • Method Detail

      • getDestinationFileName

        public java.lang.String getDestinationFileName()
        Get the name of the destination file.
        Returns:
        Returns the destination.
      • setDestinationFileName

        public void setDestinationFileName​(java.lang.String destination)
        Set the name of the destination file.
        Parameters:
        destination - The destination to set.
      • getDestinationStream

        public java.io.OutputStream getDestinationStream()
        Get the destination OutputStream.
        Returns:
        Returns the destination OutputStream.
      • setDestinationStream

        public void setDestinationStream​(java.io.OutputStream destStream)
        Set the destination OutputStream.
        Parameters:
        destStream - The destination to set.
      • addSource

        public void addSource​(java.lang.String source)
                       throws java.io.FileNotFoundException
        Add a source file to the list of files to merge.
        Parameters:
        source - Full path and file name of source document.
        Throws:
        java.io.FileNotFoundException - If the file doesn't exist
      • addSource

        public void addSource​(java.io.File source)
                       throws java.io.FileNotFoundException
        Add a source file to the list of files to merge.
        Parameters:
        source - File representing source document
        Throws:
        java.io.FileNotFoundException - If the file doesn't exist
      • addSource

        public void addSource​(org.apache.pdfbox.io.RandomAccessRead source)
        Add a source to the list of documents to merge.
        Parameters:
        source - RandomAccessRead representing source document. To pass an InputStream, wrap it into a RandomAccessReadBuffer.
      • addSources

        public void addSources​(java.util.List<org.apache.pdfbox.io.RandomAccessRead> sourcesList)
        Add a list of sources to the list of documents to merge.
        Parameters:
        sourcesList - List of RandomAccessRead objects representing source documents
      • mergeDocuments

        public void mergeDocuments​(org.apache.pdfbox.io.RandomAccessStreamCache.StreamCacheCreateFunction streamCacheCreateFunction)
                            throws java.io.IOException
        Merge the list of source documents, saving the result in the destination file. The source list is not reset after merge. If you want to merge one document at a time, then it's better to use appendDocument(org.apache.pdfbox.pdmodel.PDDocument, org.apache.pdfbox.pdmodel.PDDocument).
        Parameters:
        streamCacheCreateFunction - a function to create an instance of a stream cache; in case of null unrestricted main memory is used
        Throws:
        java.io.IOException - If there is an error saving the document.
      • mergeDocuments

        public void mergeDocuments​(org.apache.pdfbox.io.RandomAccessStreamCache.StreamCacheCreateFunction streamCacheCreateFunction,
                                   CompressParameters compressParameters)
                            throws java.io.IOException
        Merge the list of source documents, saving the result in the destination file. The source list is not reset after merge. If you want to merge one document at a time, then it's better to use appendDocument(org.apache.pdfbox.pdmodel.PDDocument, org.apache.pdfbox.pdmodel.PDDocument).
        Parameters:
        streamCacheCreateFunction - a function to create an instance of a stream cache; in case of null unrestricted main memory is used
        compressParameters - defines if compressed object streams are enabled
        Throws:
        java.io.IOException - If there is an error saving the document.
      • appendDocument

        public void appendDocument​(PDDocument destination,
                                   PDDocument source)
                            throws java.io.IOException
        append all pages from source to destination.
        Parameters:
        destination - the document to receive the pages
        source - the document originating the new pages
        Throws:
        java.io.IOException - If there is an error accessing data from either document.
      • isIgnoreAcroFormErrors

        public boolean isIgnoreAcroFormErrors()
        Indicates if acroform errors are ignored or not.
        Returns:
        true if acroform errors are ignored
      • setIgnoreAcroFormErrors

        public void setIgnoreAcroFormErrors​(boolean ignoreAcroFormErrorsValue)
        Set to true to ignore acroform errors.
        Parameters:
        ignoreAcroFormErrorsValue - true if acroform errors should be ignored