PDF merge – fast and with low overhead

XFINIUM.PDF 9.5 brings support for fast and low overhead PDF merge operations.

PDF merge was already available in XFINIUM.PDF through the PdfFixedDocument.AppendFile method.
Two or more PDF files can be merged like this:

This works fine in all situations but it can add an overhead with large PDF files because each file is parsed into the XFINIUM.PDF high level object model. The advantage is that additional operations can be performed on the merged file: bookmarks can be added for each file, pages can be watermarked, etc.

XFINIUM.PDF 9.5 brings a new method for PDF merge operations through the PdfMerger class. This utility class is specialized only in PDF merge operations, it loads and merges PDF files at a very low level without creating a full high level XFINIUM.PDF object model. The drawback is that PDF files can only be merged and that’s all, no other operations are possible.

The simplest way to merge 2 or more PDF files is to use the static method MergeFiles:

The same method also accepts streams:

With the above methods the PDF files must not be encrypted or encrypted with no password.
If the files to be merged require a password to be opened, then they can be merged like this:

The merged file can also be encrypted by providing a security handler object as parameter to the Save method.

All methods that accepts paths as parameters have overloads that accept streams as parameters.

An evaluation version of XFINIUM.PDF library can be downloaded and tried without time limitation.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.