Wednesday, March 20, 2013

Merge Pdf using pdftorn

static void MergePDF(PDFDoc new_doc, string filename) 

   using (PDFDoc in_doc = new PDFDoc(filename))  
   { 
      in_doc.InitSecurityHandler(); 
      ArrayList copy_pages = new ArrayList(); 
      for (PageIterator itr = in_doc.GetPageIterator(); itr.HasNext();itr.Next())
     { 
         copy_pages.Add(itr.Current())
      } 

   ArrayList imported_pages = new_doc.ImportPages(copy_pages); 
   for (int i=0; i!=imported_pages.Count; ++i) 
  { 
      new_doc.PagePushBack((Page)imported_pages[i]); // Order pages in reverse order. 
   } 


The following snippet shows now to merge multiple PDF documents: 
private void CallMeregPDF()
{
PDFNet.Initialize(); 
using (PDFDoc new_doc = new PDFDoc()) 

MergePDF(new_doc, @"c:\mypdfs\1.pdf"); 
MergePDF(new_doc, @"c:\mypdfs\2.pdf"); 
MergePDF(new_doc, @"c:\mypdfs\3.pdf"); 
... 
new_doc.Save("merged.pdf", , SDFDoc.SaveOptions.e_linearized); 

}

No comments:

Followers

Link