Table of Contents

Class PdfMerger

Namespace
iText.Kernel.Utils
Assembly
itext.kernel.dll

Helper class to merge a number of existing documents into one.

public class PdfMerger
Inheritance
PdfMerger
Inherited Members

Constructors

PdfMerger(PdfDocument)

This class is used to merge a number of existing documents into one.

public PdfMerger(PdfDocument pdfDocument)

Parameters

pdfDocument PdfDocument

the document into which source documents will be merged

Remarks

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.

PdfMerger(PdfDocument, bool, bool)

This class is used to merge a number of existing documents into one.

[Obsolete("use <code>PdfMerger(PdfDocument, PdfMergerProperties)</code> constructor")]
public PdfMerger(PdfDocument pdfDocument, bool mergeTags, bool mergeOutlines)

Parameters

pdfDocument PdfDocument

the document into which source documents will be merged

mergeTags bool

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 SetTagged()

mergeOutlines bool

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 InitializeOutlines()

PdfMerger(PdfDocument, PdfMergerProperties)

This class is used to merge a number of existing documents into one.

public PdfMerger(PdfDocument pdfDocument, PdfMergerProperties properties)

Parameters

pdfDocument PdfDocument

the document into which source documents will be merged

properties PdfMergerProperties

properties for the created PdfMerger

Methods

Close()

Closes the current document.

public virtual void Close()

Remarks

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.

Merge(PdfDocument, IList<int>)

This method merges pages from the source document to the current one.

public virtual PdfMerger Merge(PdfDocument from, IList<int> pages)

Parameters

from PdfDocument
  • document, from which pages will be copied
pages IList<int>
  • List of numbers of pages which will be copied

Returns

PdfMerger

this PdfMerger instance

Remarks

This method merges pages from the source document to the current one.

If closeSourceDocuments flag is set to true (see SetCloseSourceDocuments(bool) ), passed PdfDocument will be closed after pages are merged.

See also .

Merge(PdfDocument, IList<int>, IPdfPageExtraCopier)

This method merges pages from the source document to the current one.

public virtual PdfMerger Merge(PdfDocument from, IList<int> pages, IPdfPageExtraCopier copier)

Parameters

from PdfDocument
  • document, from which pages will be copied
pages IList<int>
  • List of numbers of pages which will be copied
copier IPdfPageExtraCopier
  • a copier which bears a special copy logic. May be null. It is recommended to use the same instance of IPdfPageExtraCopier for the same output document.

Returns

PdfMerger

this PdfMerger instance

Remarks

This method merges pages from the source document to the current one.

If closeSourceDocuments flag is set to true (see SetCloseSourceDocuments(bool) ), passed PdfDocument will be closed after pages are merged.

See also .

Merge(PdfDocument, int, int)

This method merges pages from the source document to the current one.

public virtual PdfMerger Merge(PdfDocument from, int fromPage, int toPage)

Parameters

from PdfDocument
  • document, from which pages will be copied
fromPage int
  • start page in the range of pages to be copied
toPage int
  • end (inclusive) page in the range to be copied

Returns

PdfMerger

this PdfMerger instance

Remarks

This method merges pages from the source document to the current one.

If closeSourceDocuments flag is set to true (see SetCloseSourceDocuments(bool) ), passed PdfDocument will be closed after pages are merged.

See also .

SetCloseSourceDocuments(bool)

If set to true then passed to the PdfMerger#merge method source documents will be closed immediately after merging specified pages into current document.

public virtual PdfMerger SetCloseSourceDocuments(bool closeSourceDocuments)

Parameters

closeSourceDocuments bool

should be true to close pdf documents in merge method

Returns

PdfMerger

this PdfMerger instance

Remarks

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.