« Wasted Disk Space in Windows 2008 due to Hiberfil.sysTranslating IEEE encoded integer values into floats using VB6 »

HOWTO: Concatenate or Merge PDF Documents


Permalink 10:42:14 pm by guy, Categories: Windows, Random Stuff , Tags: pdf, utilities

UPDATE 1/8/2009: The method I originally documented below still works really well, but most people would prefer a GUI version to the command line (me too!). I just found a project on SourceForge that is also totally free and open source that includes a GUI. The only requirement is that you have Java installed (most people do). The tool is called PDFsam for PDF split and merge. I haven’t used it extensively, but my basic tests were successful and it was very simple. Try it out at PDFsam.

Have you ever had a situation where you needed to join or concatenate 2 or more PDF documents into a single document? Or maybe you want to manipulate pages of a PDF to extract a single page or even reorder the pages? Today I had someone email me about 20 different documents in 3 different formats that they expected me to join into 3 different PDF documents.  Each document was a section or page to be contained in a final document.  This didn’t appear at first glance to be anything more than annoying, but when I started searching for a tool to use I spent a lot of time spinning my wheels.  I found MAC tools, Linux tools, and tons of the typical non-free tools.  Then I found http://www.pdfhacks.com/pdftk/  This is an open source application that does NOT have a GUI.  I’ve never been a big command line tool fan, but they certainly have their place.  Anyway, when I found this tool it was after searching for about 30 minutes so I was more open minded than usual.

This is what I did:

  1. I downloaded the pdftk zip file, and extracted the pdftk.exe file (that is the ONLY file in the zip file) into my Windows\System32 directory.  You could put it anywhere, but putting it there puts it in the path so you can run it from any other location without fully qualifying the file name.  If it had been more than one file I never would have put it there. 
  2. I converted each document to PDF.  I had a mix of Word, Excel, and PDF files supplied to me and I used the ever-reliable Cute PDF tool (http://www.cutepdf.com/Products/CutePDF/writer.asp) which is also free but not entirely open source (based on GPL Ghostscript) to do that task.  This is very easy as CutePDF shows up in ALL your Windows applications as a Printer called CutePDF.  You simply print ANY document to the CutePDF driver just like any other printer and it asks for a file name to write the document to.
  3. Collected all the PDF page documents to be merged into a single directory.
  4. Dropped to a command prompt (I know this is scary for some people!)  Click the Start Menu then the "Run" menu item and then type "cmd".
  5. Change the directory to the location of my files.  I know I shouldn’t have to say this, but you will have to type the name of the directory where you put the files, not the one I used below:

    cd \myPDFFiles
  6. Run the following command:
    pdftk.exe *.pdf cat output Outputfile.pdf

    Notice that by using an input of *.pdf it may not put the input documents in the right order (it will probably be in alphabetical order by filename) so the alternate is this:
    pdftk.exe infile1.pdf infile2.pdf infile3.pdf cat output outputfile.pdf

    This version of the command is explicitly setting the order of the files.
  7. Done!  Read the file OutputFile.pdf that it creates and you should have what you were looking for.

If you run the command pdftk --help it will give you a VERY long list of options. My example above doesn’t even begin to scratch the surface of what this tool can do. For example, it will allow you to specify more than one PDF document and then further specify only a subset of pages to output! This is a very powerful tool!

I know all this can be done using Adobe PDF tools, but I don’t own them so they don’t count!

October 2016
Sun Mon Tue Wed Thu Fri Sat
 << <   > >>
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 31          
I'm a generalist, at least if I'm honest. In my job I am primarily a developer, but also a sysadmin, and (as little as possible) technical support. I know a little about a lot of things, a lot about some things, and everything about nothing. Here I will post random learnings...


XML Feeds

User tools

powered by b2evolution