ExcelTechnology

How to Merge PDF Documents with Adobe Acrobat and C#

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

}

}

}

27.06.2011. u 06:02 | 1 Komentara | Print | # | ^

Add Word Header and Footer with C#

If a word document has many pages, people may add header or footer to show the page number. Sometimes, the header or footer may be symbols which are the topic of the document talk about or the owner of the document.

It is simple to insert add header and footer. Open a Word document. Then click Header and footer on File menu. Type the text or use the format Word provides.

Then, I want to show something about how to add Word header and footer with C#.

Using the code:

#region add Word header and footer
/**////


/// Add Header
///

/// file name
///
public static bool AddPageHeaderFooter(string filePath)
{

Try

{

Object oMissing = System.Reflection.Missing.Value;

Microsoft.Office.Interop.Word._Application WordApp = new Application();

WordApp.Visible = true;

object filename = filePath;

Microsoft.Office.Interop.Word._Document WordDoc = WordApp.Documents.Open(ref filename, ref oMissing,

ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,

ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

/**/////Method 1 to Add Header

//WordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView;

//WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader;

//WordApp.ActiveWindow.ActivePane.Selection.InsertAfter( "**" );//Header Content

/**/////Method 2 to Add Header
if (WordApp.ActiveWindow.ActivePane.View.Type == WdViewType.wdNormalView ||
WordApp.ActiveWindow.ActivePane.View.Type == WdViewType.wdOutlineView)

{

WordApp.ActiveWindow.ActivePane.View.Type = WdViewType.wdPrintView;

}

WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekCurrentPageHeader;

WordApp.Selection.HeaderFooter.LinkToPrevious = false;

WordApp.Selection.HeaderFooter.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;

WordApp.Selection.HeaderFooter.Range.Text = "Header Content";

WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekCurrentPageFooter;

WordApp.Selection.HeaderFooter.LinkToPrevious = false;

WordApp.Selection.HeaderFooter.Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;

WordApp.ActiveWindow.ActivePane.Selection.InsertAfter("Footer Content");

//Quit Header and Footer Setting

WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument;

//Save file

WordDoc.Save();

WordDoc.Close(ref oMissing, ref oMissing, ref oMissing);

WordApp.Quit(ref oMissing, ref oMissing, ref oMissing);

return true;

}

catch (Exception e)

{

Console.WriteLine(e.Message);

Console.WriteLine(e.StackTrace);

return false;

}
}
#endregion Add Word header and footer

Sometimes, programmers may use components. The components can save programmers much of time to write code and deal with a large amount of documents quickly.

To sum up, in this article, I shows the method to add Word header and footer by using C# and hope it will be helpful for you.

01.06.2011. u 07:27 | 0 Komentara | Print | # | ^

<< Prethodni mjesec | Sljedeći mjesec >>

Creative Commons License
Ovaj blog je ustupljen pod Creative Commons licencom Imenovanje-Dijeli pod istim uvjetima.

< lipanj, 2011 >
P U S Č P S N
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30      

Kolovoz 2011 (2)
Srpanj 2011 (2)
Lipanj 2011 (2)
Svibanj 2011 (2)
Travanj 2011 (3)
Ožujak 2011 (2)
Veljača 2011 (2)
Siječanj 2011 (5)
Prosinac 2010 (5)

Dnevnik.hr
Gol.hr
Zadovoljna.hr
Novaplus.hr
NovaTV.hr
DomaTV.hr
Mojamini.tv

Opis bloga

something about Excel Technology in VB.Net and C#

Linkovi

Dnevnik.hr
Video news portal Nove TV

Blog.hr
Blog servis

Igre.hr
Najbolje igre i igrice

Forum.hr
Monitor.hr