Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A one-line PDF merge command UNIX
The need arose today to merge several PDF files into one long PDF file. I looked at previous hints (1, 2), but they did not satisfy me as they forced me to enter the world of Tex.

Here is the simplest solution I came up with. As far as I know, GhostScript (gs) is included in OS X by default. In the Terminal, type:

gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=merged.pdf \
source1.pdf source2.pdf source3.pdf etc.pdf
All of that is one long line; it's been broken here with the backslash, so it should just copy and paste into the Terminal. It seems easy enough to wrap an AppleScript around this, as well. The -q (quiet) parameter can be omitted if you wish to see gs tell you what it's doing.

[robg adds: My PowerBook G4 has been very recently restored to a default 10.2.6 install, and GhostScript is not present, so I don't think it's included -- there's a previous hint that explains how to install it.]
  • Currently 4.38 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (8 votes cast)

A one-line PDF merge command | 9 comments | Create New Account
Click here to return to the 'A one-line PDF merge command' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A one-line PDF merge command
Authored by: ejknapp on Sep 03, '03 11:03:36AM

I installed gs using fink and the hint's command works fine. I have been looking for this for a while. Thanks!

[ Reply to This | # ]
A one-line PDF merge command
Authored by: themostbob on Sep 03, '03 12:23:36PM
joinPDF worked for me. I don't think it requires gs.

[ Reply to This | # ]
A one-line PDF merge command
Authored by: bluehz on Sep 03, '03 07:51:56PM

I also use joinPDF... but never hurts to have several methods.

[ Reply to This | # ]
Authored by: KrazyFool on Sep 04, '03 01:34:21AM

There is an easy point click installer here for GhostScript, I think this is what you mean...

[ Reply to This | # ]
A one-line PDF merge command with difficult PDF files
Authored by: ces3001 on Sep 04, '03 02:57:46AM

I ran into a PDF file (from Apple ironically enough) that causes gs to choke (bus error). That file opens fine in Acrobat Reader and in Preview, so I just printed again to a temp.PDF and used the temp.PDF with GhostScript. Worked fine.

[ Reply to This | # ]
Other uses for gs
Authored by: ces3001 on Sep 04, '03 03:05:53AM

What's nice about Ghostscript is that it can merge PDFs, or any PostScript source file into a number of output formats including JPEG, PCX, BMP, etc.

To get the list, type gs at the unix prompt. you'll get a GS> prompt, where you type "devicenames ==" (without the quotes).

My list (don't know if it's standard or not) looks like:
[/pcxcmyk /epswrite /bj200 /bitcmyk /lj5mono /tiffg32d /bmpa16m /pgnmraw /bmpsep1 /pcxmono /jpeg /pj /psmono /ljet2p /pkmraw /bmpamono /pbm /pxlmono /bjc600 /pngmono /lj5gray /tiffg4 /bmpa32b /pnm /bmpsep8 /pcxgray /jpeggray /pjxl /psgray /ljet3 /pksm /bmpasep1 /pbmraw /pxlcolor /bjc800 /pnggray /cdeskjet /tifflzw /deskjet /pnmraw /bmp16 /pcx16 /pdfwrite /pjxl300 /psrgb /ljet3d /pksmraw /bmpasep8 /pgm /cljet5 /faxg3 /png16 /cdjcolor /tiffpack /djet500 /ppm /bmp256 /pcx256 /bbox /uniprint /bit /ljet4 /tiffcrle /bmpa16 /pgmraw /cljet5c /bmpmono /faxg32d /png256 /cdjmono /tiff12nc /laserjet /ppmraw /bmp16m /pcx24b /pswrite /bj10e /bitrgb /ljet4d /tiffg3 /bmpa256 /pgnm /nullpage /bmpgray /faxg4 /png16m /cdj550 /tiff24nc /ljetplus /pkm /bmp32b]

Use one of these (without the /) in the -dDEVICE=xxxx command line parameter instead of PDFwrite to use it.

(To get out of GS, type "quit" and hit return.)

For more info, issue the following command at the unix prompt
man gs

[ Reply to This | # ]
A one-line PDF merge command
Authored by: qoo77 on Dec 16, '03 02:43:55PM

the merged PDF generated showed some quirks ... using the GUI app Combine PDFs is so much easier...

[ Reply to This | # ]
Authored by: kd4ttc on Apr 03, '06 06:19:40PM

pdftk works on 10.4.x

Merge Two or More PDFs into a New Document
pdftk 1.pdf 2.pdf 3.pdf cat output 123.pdf

or (Using Handles):
pdftk A=1.pdf B=2.pdf cat A B output 12.pdf

or (Using Wildcards):
pdftk *.pdf cat output combined.pdf

Steve Holland

[ Reply to This | # ]
A one-line PDF merge command
Authored by: cekim on Mar 31, '08 10:46:19AM