Merge Multiple PDF Files into One in WPF

Before we start our topic, let us first play a game. At the top of this page, there are nine categories. When we move our mouse on .NET, a dropdown list which shows all e-iceblue .NET products is displayed as the picture below:
Merge PDF Documents

Imagine, if we demonstrate every product on .NET out of the dropdown list on the top, what will this page be? The webpage will be rambling and disordered. As a result, visitors will hardly search what they want and finally have to leave disappointedly.

By the same token, if we do not merge PDF files of similar content to one document, all the information of various classes will mix together. We have no choice but to spend much time on finding the right files. While our work turns more efficient when we use PDF merge function. Furthermore, opening more PDF files at the same time always annoys people in that the windows are mistakenly switched. Finally, merge PDF does not mean gathering tens of PDF files into one. More reasonable choice is to amalgamate PDF files of few pages into single one. Those of numerous pages should be combined with merged PDF files in one folder for the convenience of reading.

Spire.PDF for WPF, as a professional PDF component, is a best hand for users to merge multiple PDF files on WPF application with C#, VB.NET. The whole procedure can be performed by below three simple steps.

Step 1 Create a C#/VB.NET Project

  1. Free download and correctly install Spire.PDF for WPF on system.
  2. Create “PDF merge” project in WPF Application with C#/VB.NET.
  3. Add a button in MainWindow.
  4. Add Spire.Pdf.Wpf.dll and System.Drawing as references.

Step 2 Merge PDF Files into One

1. Load three PDF documents from system.
[C#]
            //pdf document list
            String[] files = new String[]
            {
                @"D:\e-iceblue\Spire.PDF\Demos\Data\DigitalSignature.pdf",
                @"D:\e-iceblue\Spire.PDF\Demos\Data\Sample2.pdf",
                @"D:\e-iceblue\Spire.PDF\Demos\Data\ImageWaterMark.pdf"                            
            };
[VB.NET]
'pdf document list
Dim files As [String]() = New [String]() {"D:\e-iceblue\Spire.PDF\Demos\Data\DigitalSignature.pdf", "D:\e-iceblue\Spire.PDF\Demos\Data\Sample2.pdf", "D:\e-iceblue\Spire.PDF\Demos\Data\ImageWaterMark.pdf"}
          
2. Open the three PDF files in a new document and import all pages into a new one.
[C#]
           //open pdf documents            
            PdfDocument[] docs = new PdfDocument[files.Length];
            for (int i = 0; i < files.Length; i++)
            {
                docs[i] = new PdfDocument(files[i]);
            }
            //append document
            docs[0].AppendPage(docs[1]);
            //import pages
            for (int i = 0; i < docs[2].Pages.Count; i = i + 2)
            {
                docs[0].InsertPage(docs[2], i);
            }
[VB.NET]
	'open pdf documents            
	Dim docs As PdfDocument() = New PdfDocument(files.Length - 1) {}
	For i As Integer = 0 To files.Length - 1
		docs(i) = New PdfDocument(files(i))
	Next
	'append document
	docs(0).AppendPage(docs(1))
	'import pages
	Dim i As Integer = 0
	While i < docs(2).Pages.Count
		docs(0).InsertPage(docs(2), i)
		i = i + 2
	End While
          

Step3. Save and Preview the Merged PDF File.

[C#]
            docs[0].SaveToFile("MergeDocuments.pdf");
            foreach (PdfDocument doc in docs)
            {
                doc.Close();
            }
            PDFDocumentViewer("MergeDocuments.pdf");
[VB.NET]
docs(0).SaveToFile("MergeDocuments.pdf")
For Each doc As PdfDocument In docs
	doc.Close()
Next
PDFDocumentViewer("MergeDocuments.pdf")
Effective Screeshot
Merge PDF Documents

Spire.PDF is a PDF document creation component that enables your .NET/Silverlight/WPF applications to read, write and manipulate PDF documents without using Adobe Acrobat.

PDF Family
PDF Family has three members: Spire.PDF for .NET, Spire.PDF for Silverlight and Spire.PDF for WPF, which are packed in Spire.PDF. Spire.PDF enables your .NET /Silverlight/WPF applications to easily manage your PDF documents.