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:
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
- Free download and correctly install Spire.PDF for WPF on system.
- Create “PDF merge” project in WPF Application with C#/VB.NET.
- Add a button in MainWindow.
- Add Spire.Pdf.Wpf.dll and System.Drawing as references.
Step 2 Merge PDF Files into One
//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" };
'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"}
Step 2. Open the three PDF files in a new document and import all pages into a new one
//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); }
'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
Step 3. Save and Preview the Merged PDF File
docs[0].SaveToFile("MergeDocuments.pdf"); foreach (PdfDocument doc in docs) { doc.Close(); } PDFDocumentViewer("MergeDocuments.pdf");
docs(0).SaveToFile("MergeDocuments.pdf") For Each doc As PdfDocument In docs doc.Close() Next PDFDocumentViewer("MergeDocuments.pdf")
Effective Screeshot
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.