Class PdfMerger


  • public class PdfMerger
    extends java.lang.Object
    Helper class to merge a number of existing documents into one.
    • Constructor Summary

      Constructors 
      Constructor Description
      PdfMerger​(PdfDocument pdfDocument)
      This class is used to merge a number of existing documents into one.
      PdfMerger​(PdfDocument pdfDocument, boolean mergeTags, boolean mergeOutlines)
      Deprecated.
      use PdfMerger(PdfDocument, PdfMergerProperties) constructor
      PdfMerger​(PdfDocument pdfDocument, PdfMergerProperties properties)
      This class is used to merge a number of existing documents into one.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes the current document.
      PdfMerger merge​(PdfDocument from, int fromPage, int toPage)
      This method merges pages from the source document to the current one.
      PdfMerger merge​(PdfDocument from, java.util.List<java.lang.Integer> pages)
      This method merges pages from the source document to the current one.
      PdfMerger merge​(PdfDocument from, java.util.List<java.lang.Integer> pages, IPdfPageExtraCopier copier)
      This method merges pages from the source document to the current one.
      PdfMerger setCloseSourceDocuments​(boolean closeSourceDocuments)
      If set to true then passed to the PdfMerger#merge method source documents will be closed immediately after merging specified pages into current document.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PdfMerger

        public PdfMerger​(PdfDocument pdfDocument)
        This class is used to merge a number of existing documents into one. By default, if source document contains tags and outlines, they will be also copied to the destination document.
        Parameters:
        pdfDocument - the document into which source documents will be merged
      • PdfMerger

        @Deprecated
        public PdfMerger​(PdfDocument pdfDocument,
                         boolean mergeTags,
                         boolean mergeOutlines)
        Deprecated.
        use PdfMerger(PdfDocument, PdfMergerProperties) constructor
        This class is used to merge a number of existing documents into one.
        Parameters:
        pdfDocument - the document into which source documents will be merged
        mergeTags - if true, then tags from the source document are copied even if destination document is not set as tagged. Note, that if false, tag structure is still could be copied if the destination document is explicitly marked as tagged with PdfDocument.setTagged()
        mergeOutlines - if true, then outlines from the source document are copied even if in destination document outlines are not initialized. Note, that if false, outlines are still could be copied if the destination document outlines were explicitly initialized with PdfDocument.initializeOutlines()
      • PdfMerger

        public PdfMerger​(PdfDocument pdfDocument,
                         PdfMergerProperties properties)
        This class is used to merge a number of existing documents into one.
        Parameters:
        pdfDocument - the document into which source documents will be merged
        properties - properties for the created PdfMerger
    • Method Detail

      • setCloseSourceDocuments

        public PdfMerger setCloseSourceDocuments​(boolean closeSourceDocuments)
        If set to true then passed to the PdfMerger#merge method source documents will be closed immediately after merging specified pages into current document. If false - PdfDocuments are left open. Default value - false.
        Parameters:
        closeSourceDocuments - should be true to close pdf documents in merge method
        Returns:
        this PdfMerger instance
      • close

        public void close()
        Closes the current document.

        It is a complete equivalent of calling PdfDocument#close on the PdfDocument passed to the constructor of this PdfMerger instance. This means that it is enough to call close either on passed PdfDocument or on this PdfMerger instance, but there is no need to call them both.