PDFOne .NET
Powerful all-in-one PDF library for .NET
Compatibility
VS 2005/2008/2010/2012/2013

How To Merge PDF Documents In .NET

Learn to use PDFOne .NET to merge PDF documents.
By V. Subhash

This article is based on a personal experience. No, it's not meant to make you misty-eyed or something. This is just to illustrate how PDFOne .NET can help you accomplish real-life PDF-related tasks. That's it.

Being an hardware enthusiast, I like to read hard copies of ASUS World magazine that our office gets by post. One day, I went to the ASUS website hoping to get a newer copy of the magazine. The site gave me a ZIP download containing not one but several PDF documents!

These PDFs were heavy and opening them individually was not very conducive for casual browsing. I then decided to merge the documents together using one of our PDF tools. Here are the steps for my PDFOne .NET solution.

  1. Open Visual Studio and create a C# Forms application project.

  2. Add reference to PDFOne.dll.
  3. Drop a "File Open Dialog" Windows component ( System.Windows.Forms.OpenFileDialog) on the form.
  4. Drop a button on the form and add this code for the event handler.
    private void button1_Click(object sender, EventArgs e) {
    
      String[] saFiles;
      ArrayList alFiles = new ArrayList();
      PDFDocument doc;
      // Show "File Open" dialog
      openFileDialog1.Filter = "PDF files (*.pdf)|*.pdf";
      openFileDialog1.Multiselect = true;
      openFileDialog1.ShowDialog();
    
      saFiles = openFileDialog1.FileNames;
    
      if (saFiles.Length > 1) {
        // Place selected PDF files in an array list
        foreach (String sFile in saFiles) {
            alFiles.Add(sFile);
        }
    
        doc = new PDFDocument("your license key");
        doc.OpenAfterCreate = true;
    
        // Merge the PDF documents
        doc.Merge(alFiles);
        doc.Save("merged.pdf");
    
        doc.Close();
      }
    
    }
    
  5. Add a Using directive for Gnostice.PDFOne so that the above code compiles.
  6. Run the project.
  7. Click the button to display the "File Open" dialog.
  8. Select PDF documents that need to be merged and click OK to begin the merge operation.

The PDFDocument.Merge() method accepts an array list containing the pathnames of the PDF documents that need to be merged. Calling this method, merges the document into one file. Here is the output I got. Sweet!

---o0O0o---

Our .NET Developer Tools
Gnostice Document Studio .NET

Multi-format document-processing component suite for .NET developers.

PDFOne .NET

A .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications.

Our Delphi/C++Builder developer tools
Gnostice Document Studio Delphi

Multi-format document-processing component suite for Delphi/C++Builder developers, covering both VCL and FireMonkey platforms.

eDocEngine VCL

A Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools.

PDFtoolkit VCL

A Delphi/C++Builder component suite to edit, enhance, view, print, merge, split, encrypt, annotate, and bookmark PDF documents.

Our Java developer tools
Gnostice Document Studio Java

Multi-format document-processing component suite for Java developers.

PDFOne (for Java)

A Java PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java applications.

Our Platform-Agnostic Cloud and On-Premises APIs
StarDocs

Cloud-hosted and On-Premises REST-based document-processing and document-viewing APIs

Privacy | Legal | Feedback | Newsletter | Blog | Resellers © 2002-2024 Gnostice Information Technologies Private Limited. All rights reserved.