Class PdfMerger
- java.lang.Object
-
- com.itextpdf.kernel.utils.PdfMerger
-
public class PdfMerger extends java.lang.ObjectHelper class to merge a number of existing documents into one.
-
-
Field Summary
Fields Modifier and Type Field Description private PdfDocumentpdfDocumentprivate PdfMergerPropertiesproperties
-
Constructor Summary
Constructors Constructor Description PdfMerger(PdfDocument pdfDocument)This class is used to merge a number of existing documents into one.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 voidclose()Closes the current document.PdfMergermerge(PdfDocument from, int fromPage, int toPage)This method merges pages from the source document to the current one.PdfMergermerge(PdfDocument from, java.util.List<java.lang.Integer> pages)This method merges pages from the source document to the current one.PdfMergermerge(PdfDocument from, java.util.List<java.lang.Integer> pages, IPdfPageExtraCopier copier)This method merges pages from the source document to the current one.PdfMergersetCloseSourceDocuments(boolean closeSourceDocuments)If set to true then passed to thePdfMerger#mergemethod source documents will be closed immediately after merging specified pages into current document.
-
-
-
Field Detail
-
pdfDocument
private PdfDocument pdfDocument
-
properties
private PdfMergerProperties properties
-
-
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
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 mergedproperties- properties for the createdPdfMerger
-
-
Method Detail
-
setCloseSourceDocuments
public PdfMerger setCloseSourceDocuments(boolean closeSourceDocuments)
If set to true then passed to thePdfMerger#mergemethod 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
PdfMergerinstance
-
merge
public PdfMerger merge(PdfDocument from, int fromPage, int toPage)
This method merges pages from the source document to the current one.If closeSourceDocuments flag is set to true (see
setCloseSourceDocuments(boolean)), passedPdfDocumentwill be closed after pages are merged.See also
PdfDocument.copyPagesTo(int, int, com.itextpdf.kernel.pdf.PdfDocument, int).- Parameters:
from- - document, from which pages will be copiedfromPage- - start page in the range of pages to be copiedtoPage- - end (inclusive) page in the range to be copied- Returns:
- this
PdfMergerinstance
-
merge
public PdfMerger merge(PdfDocument from, java.util.List<java.lang.Integer> pages)
This method merges pages from the source document to the current one.If closeSourceDocuments flag is set to true (see
setCloseSourceDocuments(boolean)), passedPdfDocumentwill be closed after pages are merged.See also
PdfDocument.copyPagesTo(int, int, com.itextpdf.kernel.pdf.PdfDocument, int).- Parameters:
from- - document, from which pages will be copiedpages- - List of numbers of pages which will be copied- Returns:
- this
PdfMergerinstance
-
merge
public 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.If closeSourceDocuments flag is set to true (see
setCloseSourceDocuments(boolean)), passedPdfDocumentwill be closed after pages are merged.See also
PdfDocument.copyPagesTo(int, int, com.itextpdf.kernel.pdf.PdfDocument, int).- Parameters:
from- - document, from which pages will be copiedpages- - List of numbers of pages which will be copiedcopier- - a copier which bears a special copy logic. May be null. It is recommended to use the same instance ofIPdfPageExtraCopierfor the same output document.- Returns:
- this
PdfMergerinstance
-
close
public void close()
Closes the current document.It is a complete equivalent of calling
PdfDocument#closeon 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.
-
-