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

HOWTO: Concatenate or Merge PDF Documents

01/12/09

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!

9 comments

Comment from: Alan W [Visitor]
Excellent information -- thank you very much!!
09/29/09 @ 16:02
Comment from: Brian Ruckley [Visitor] Email
After downloading the zip file, it asks for a password when you try to unzip it. Any ideas?
11/10/09 @ 23:28
Comment from: Lara van Niekerk [Visitor]
Sounds like great fun for someone that knows their way around a computer... But I was searching around for something my mother can use. hahaha so obviously NOT the cmd. What I did find tho is a free trial version that works great! http://www.a-pdf.com/merger/index.htm
11/27/09 @ 07:08
Comment from: PDF concatenate [Visitor] · http://www.addpdffiles.com
nice www.addpdffiles.com site for the pdf tools
12/18/09 @ 02:54
Comment from: Ken Meyers [Visitor]
A simpler solution would be to download a free software application at "PrimoPDF.com". This will install a new 'virtual printer' on your system called PrimoPdf. When you have a file (Word, Excel, etc.) that you want in PDF form, just print to the PrimoPDF printer. One of the parameters you supply is where you want the PDF file to be stored (location and file name). If you wish to concatenate 2 or more files, just supply the same location and file name for each file. The software recognizes the duplicate name and gives you a choice to replace the already existing PDF file or "Append" the current file to the existing file. Select 'Append' to give you the concatenated PDF file you are looking for.
02/07/10 @ 08:11
Comment from: YoAdobe [Visitor] · http://www.pdfmerge.com
Another simple solution for those not inclined to use command line tools is http://www.pdfmerge.com, one of many free online services.
05/23/10 @ 11:00
Comment from: Michael Shigorin [Visitor] Email · http://www.altlinux.org
2 Lara van Niekerk: A-PDF trial spoils (that is, watermarks) its output -- you should have mentioned that.

2 Ken Meyers: PrimoPDF installs just fine on winxp then dies silently (as a filter) or with an "error 0xc0000135" (as a drop-box). Seems a current version is a .NET crap.
07/06/10 @ 14:31
Comment from: keanu [Visitor]
i very thank you, u save me lot of time, this pdftk is GREAT tool, once again thank you very much :)
11/05/10 @ 03:14
Comment from: Geoff Wilkie [Visitor]
PDFCreator lets you create and concatenate PDFs. It also lets you print in other formats such as JPEG. That can be handy in Yahoo Groups, for instance, where you get lots more storage space for graphics than other types of files. It's available for free through http://downloads.cnet.com/.
01/31/11 @ 22:07

Comments are closed for this post.

July 2014
Sun Mon Tue Wed Thu Fri Sat
 << <   > >>
    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 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...

Search

XML Feeds

User tools

powered by b2evolution