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

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.

C#

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);

      }

}

VB.NET

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?

poor 
1
2
3
4
5
6
7
8
9
10

 excellent
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, 2017. InstantASP Ltd. All Rights Reserved