How to Merge PDF Files
Why Merge PDF Files
PDF developers or normal office workers may handle tons of PDF documents in a single day. With a large number of PDF files, they need an efficient way to work with the PDF files. When document management becomes an issue, merging selective PDFs together can make it easier to control the content of file folders. And this gives us an option of creating more organized PDF documents. In addition, we can maintain and improve our level of proficiency and decrease the amount of separate individual tasks by working with merged-and fewer PDF documents.
How to Merge PDF Files
Through Adobe Acrobat, users can merge PDF files together by opening all the PDF files which need to be merged and clicking the ‘Combine Files’ icon on the top left portion of the screen. However, we can merge PDF files without opening PDF files and Adobe Acrobat installed on system. By using Spire.PDF, we can easily use C# to merge PDF files.
Download Spire.PDF Here
Ensure Spire.PDF and Visual Studio correctly installed on system. Follow the simple steps below to merge PDF files into one.
Step 1 Create a Project
Create a C# project in Visual Studio and Add Spire.Pdf.dll as reference. The default setting of Spire.Pdf.dll is placed under "C:\Program Files\e-iceblue\Spire.Pdf\Bin”. Select assembly Spire.Pdf.dll and click OK to add it to the project.
using System;
using Spire.Pdf;
namespace MergePDF
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
}
}
}
Step 2 Make PDF Document List
Put all the PDF files into the project folder. List them in the project like the code below.
//pdf document list
String[] files = new String[]
{
@"Sample3.pdf",
@"Sample2.pdf",
@"Sample1.pdf"
};
Step 3 Merge PDF Files
Open all the PDF files in a New PDF document and import the pages into the 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 page
for (int i = 0; i < docs[2].Pages.Count; i = i + 2)
{
docs[0].InsertPage(docs[2], i);
}
Step 4 Save and Preview
Use the code below to save and preview what we did.
//Save pdf file.
docs[0].SaveToFile("MergeDocuments.pdf");
//close
foreach (PdfDocument doc in docs)
{
doc.Close();
}
//Launching the Pdf file.
System.Diagnostics.Process.Start("MergeDocuments.pdf");
After finish coding the whole project, press F5 to launch the project. Then, you can find the merged PDF document in the project bin->debug folder.
More about Spire.PDF
Spire.PDF is a PDF document creation component that enables your .NET/Silverlight applications to read, write and manipulate PDF documents without using Adobe Acrobat. Click to learn more…
PDF developers or normal office workers may handle tons of PDF documents in a single day. With a large number of PDF files, they need an efficient way to work with the PDF files. When document management becomes an issue, merging selective PDFs together can make it easier to control the content of file folders. And this gives us an option of creating more organized PDF documents. In addition, we can maintain and improve our level of proficiency and decrease the amount of separate individual tasks by working with merged-and fewer PDF documents.
How to Merge PDF Files
Through Adobe Acrobat, users can merge PDF files together by opening all the PDF files which need to be merged and clicking the ‘Combine Files’ icon on the top left portion of the screen. However, we can merge PDF files without opening PDF files and Adobe Acrobat installed on system. By using Spire.PDF, we can easily use C# to merge PDF files.
Download Spire.PDF Here
Ensure Spire.PDF and Visual Studio correctly installed on system. Follow the simple steps below to merge PDF files into one.
Step 1 Create a Project
Create a C# project in Visual Studio and Add Spire.Pdf.dll as reference. The default setting of Spire.Pdf.dll is placed under "C:\Program Files\e-iceblue\Spire.Pdf\Bin”. Select assembly Spire.Pdf.dll and click OK to add it to the project.
using System;
using Spire.Pdf;
namespace MergePDF
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
}
}
}
Step 2 Make PDF Document List
Put all the PDF files into the project folder. List them in the project like the code below.
//pdf document list
String[] files = new String[]
{
@"Sample3.pdf",
@"Sample2.pdf",
@"Sample1.pdf"
};
Step 3 Merge PDF Files
Open all the PDF files in a New PDF document and import the pages into the 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 page
for (int i = 0; i < docs[2].Pages.Count; i = i + 2)
{
docs[0].InsertPage(docs[2], i);
}
Step 4 Save and Preview
Use the code below to save and preview what we did.
//Save pdf file.
docs[0].SaveToFile("MergeDocuments.pdf");
//close
foreach (PdfDocument doc in docs)
{
doc.Close();
}
//Launching the Pdf file.
System.Diagnostics.Process.Start("MergeDocuments.pdf");
After finish coding the whole project, press F5 to launch the project. Then, you can find the merged PDF document in the project bin->debug folder.
More about Spire.PDF
Spire.PDF is a PDF document creation component that enables your .NET/Silverlight applications to read, write and manipulate PDF documents without using Adobe Acrobat. Click to learn more…