Home : DotPdf : Merge Two Pdf Files Into One
Q10261 - HOWTO: Merge Two Pdf Files Into One

Legacy Example NOTICE

This article predates the introduction of our PdfDocument class. PdfDocument has a Combine method which is much more efficient for combining two or more PDF files. Support strongly recommends using this newer class for this task

Q10429 - HOWTO: Combine Multiple PDFs with Automatic Repair of Damaged PDFs

Q10428 - HOWTO: Combine Multiple PDF Files With Fillable Forms (AcroForms)

Q10430 - HOWTO: Separate a Multi-Page PDF With Automatic Repair of Damaged PDFs

Main Article Content

With the PdfRasterizer add-on, merging two Pdf files into one is a simple coding task. First combine the two file paths into one string array. Then use that array to construct a FileSystemImageSource object. Then using a PdfEncoder, call the Save method overload that takes an ImageSource.


static Form1()


    RegisteredDecoders.Decoders.Add(new PdfDecoder());



private void MergePdfs(string FirstFilePath, string SecondFilePath, string OutputPath)


FileSystemImageSource fsis = new FileSystemImageSource(new string[]{ FirstFilePath, SecondFilePath }, true);

      using (FileStream fs = new FileStream(OutputPath, FileMode.OpenOrCreate))


         PdfEncoder encoder = new PdfEncoder();

         encoder.Save(fs, fsis, null);




Shared Sub New()

    RegisteredDecoders.Decoders.Add(New PdfDecoder())

End Sub


Private Sub MergePdfs(ByVal FirstFilePath As String, ByVal SecondFilePath As String, ByVal OutputPath As String)

Dim fsis As New FileSystemImageSource(New String() {FirstFilePath, SecondFilePath}, True)

    Using fs As New FileStream(OutputPath, FileMode.OpenOrCreate)

        Dim encoder As New PdfEncoder()

        encoder.Save(fs, fsis, Nothing)

    End Using

End Sub

Combining Without Rasterizing

If you're using DotImage 10.0 or newer or DotPdf, You can combine two or more PDFs together using our PdfDocument Classes static Combine method:

void PdfDocument.Combine(String outputPdfPath, string[] arrayOfSourcePdfFilePaths);

For more on PdfDocument.Combine please see the API reference

PdfDocument.Combine(string, string[])

PdfDocument.Combine(Stream, Stream[])

Related Articles
No Related Articles Available.

Article Attachments
No Attachments Available.

Related External Links
No Related Links Available.
Help us improve this article...
What did you think of this article?


Tell us why you rated the content this way. (optional)
Approved Comments...
No user comments available for this article.

Powered By InstantKB.NET v1.3
Copyright © 2002, 2019. InstantASP Ltd. All Rights Reserved