I have posted other utilities for handling PDF files in previous blog posts. For example, here is a post I wrote to deal with adding or removing password protection from PDF files. The source code is available here.  If you want the executables, they are here.

Recently, I needed to combine a number of PDF files into a single file so that I could password protect and email just one document.  Incredibly, I could not find anything on the web that was free that allowed me to do this.  So back to the PDF Sharp library and a simple console app to the rescue.

The source code is here; and the executable is here.

Quick start instructions:

  1. Put the pdf files you want to combine in  folder; let’s say c:\temp
  2. Download and extract the executable and/or the source and compile it yourself.  You will need the compiled PDFSharp.dll in the same folder as the executable.
  3. Open a command prompt and navigate to the folder where you have the MergePDFs.exe file.
  4. Execute the MergePDFs.exe file.  You can add the arguments as follows; or just execute the program and it will give you the following information:
      1. Argument 1:  Directory name where the pdf files are held.  Note that all PDF files found in the source folder will be merged.
      2. Argument 2: Output directory and file name of the combined PDF file.  If you want to use the same folder as the source folder, just key in a . and filename: “.myfile.pdf”
      3. Argument 3: is the sort by for the combination:
        1. “D” is for sort by date
        2. “A” is for sort by name in alpha order
        3. “N” is for no sort
    1. Argument 4: is a password to apply to the new file.

For example, to merge all PDF files in our c:\temp folder, to sort by date, and to put a password of “12345” on the document, you would execute the following:

“MergePdfs.exe c:\temp c:\targetPdfFolder\Newfile.pdf D 12345”

Disclaimer:  This is a quick utility that I wrote to serve my immediate needs.  It has not been fully tested and so I would not release this as a production app.  But it works.  However, YMMV.  Post comments and questions below.

Leave a Reply

Your email address will not be published. Required fields are marked *