I often download several documents from internet when I need to collect materials to write one technical article. However, it is possible that the contents of one document are similar to others. And one of the documents introduces one aspect of the topic which another document shows. Therefore, I want to merge two or more documents into one. If I want to print the documents, I can save many pieces of paper as well.
At present, PDF are widely used so that many documents I download are PDF documents. Actually, if I want to merge PDF, I need to use some tools to help me, for example, Adobe Acrobat.
Use Adobe Acrobat to open PDF file. Confirm the first page of the merged PDF. Click Combine Files. Then, a window pops up. Select Add Open Files option to choose merged files. After that, another window pops up for arranging the order of merged files. And then, set the file size. Also, there are some other settings. We can choose the most suitable settings according to our requirement. Finally, select to merge to a single file or a package and click Create to get the new document.
Besides, I get another method to merge PDF with C#. I want to show this method because I am learning C# right now and I think that this method may be helpful for some programmers.
Note: This method is based on a component: Spire.PDF. Download it before using the following code.
using System;
using Spire.Pdf;
namespace MergeDocuments
{
class Program
{
static void Main(string[] args)
{
//pdf document list
String[] files = new String[]
{
@"Sample3.pdf",
@"Sample2.pdf",
@"Sample1.pdf"
};
//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);
}
//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");
}
}
}
Post je objavljen 27.06.2011. u 06:02 sati.