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

Stitching together multiple PDFs with ghostscript UNIX
I needed a quick and dirty way to stitch PDF together and going through the web and through macosxhints, I found some ways but all seemed to be either too complicated or required downloading lots of stuff. I found a solution here, though, that's quite simple (assuming you have fink installed). Basically what you need to do is issue:
 % fink install ghostscript6
and then (after issuing a rehash):
 % gs -q -sPAPERSIZE=a4 -dNOPAUSE -dBATCH -sDEVICE=pdfwrite \
   -sOutputFile=output.pdf pdf1.pdf pdf2.pdf
The command above (it's one line, as shown by the \) will basically create one outputfile called output.pdf that consists of pdf1.pdf and pdf2.pdf. You can replace pdf1.pdf with *.pdf and it will grab all the pdf files and output one pdf. That's all.

[robg adds: I haven't tested this one...]
    •    
  • Currently 4.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (4 votes cast)
 
[14,120 views]  

Stitching together multiple PDFs with ghostscript | 19 comments | Create New Account
Click here to return to the 'Stitching together multiple PDFs with ghostscript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Stitching together multiple PDFs with ghostscript
Authored by: betamonkey on Feb 26, '03 11:48:24AM

Fink couldn't get the ghostscript-6.50jpeg.tar.gz file downloaded from the mirror that it needs to download from, thus leaving my install hanging.
I tried pinging the address, but it doesn't respond so it must be down.



[ Reply to This | # ]
workaround
Authored by: betamonkey on Feb 26, '03 12:25:04PM

I did, however get it to work by following the steps found <a href="http://www.macwrite.com/criticalmass/ghostscript-for-mac-os-x.php">here</a>.

When you try to download the files from the Wisc.edu site, be aware that it will mount the FTP server on your desktop in Jaguar instead of simply downloading it.



[ Reply to This | # ]
Stitching together multiple PDFs with ghostscript
Authored by: secundar on Feb 26, '03 12:35:11PM

GS is installed and appears to process the pages but all i get is a multi-page pdf with blank (white pages). I trited this with Ghostscript6 and version 7 with no luck.

I'm not UNIX savvy. Any advice?



[ Reply to This | # ]
blank pages
Authored by: betamonkey on Feb 26, '03 01:47:57PM

could you paste the command you typed into the terminal over here so I can see what's going on?



[ Reply to This | # ]
blank pages
Authored by: secundar on Feb 26, '03 05:21:48PM
% gs -q -sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=output.pdf *.pdf

I basically cut and pasted from the hint and changed the input file param.

GNU Ghostscript 7.05 (2002-04-22) but i also tried it with Ghostscript 6.01-2

thanks for your help

[ Reply to This | # ]

blank pages
Authored by: ajmas on Feb 26, '03 07:49:33PM

what happens if you specifiy a different folder for the destination file?



[ Reply to This | # ]
Stitching together multiple PDFs with ghostscript
Authored by: macman13 on Feb 26, '03 01:48:47PM

I installed gs with fink and I get the following:

dyld: gs can't open library: libpng.5.dylib (No such file or directory, errno = 2)
Trace/BPT trap

Anyone know how to fix this??

Thanks.
SA

---
\\\"I can do everything on my Mac I used to do on my PC, plus alot more ...\\\"
--Me



[ Reply to This | # ]
Stitching together multiple PDFs with ghostscript
Authored by: betamonkey on Feb 26, '03 01:57:13PM
try downloading the file from here. Note: When you hit the link to download the files, it will mount a sever on your desktop in Jaguar

[ Reply to This | # ]
Stitching together multiple PDFs with ghostscript
Authored by: slowco on Feb 26, '03 03:37:02PM

Try "fink install libpng3" or "fink install libpng"



[ Reply to This | # ]
Stitching together multiple PDFs with ghostscript
Authored by: macman13 on Feb 27, '03 01:41:55PM

Nope.

Already did that.

Something wrong with Fink's install I believe.

SA
:)

---
\\\"I can do everything on my Mac I used to do on my PC, plus alot more ...\\\"
--Me



[ Reply to This | # ]
Stitching together multiple PDFs with ghostscript
Authored by: geohar on Feb 26, '03 01:55:33PM
I'd recommend going to Gerben Wierda's page http://www.rna.nl/ii.html and using iInstaller to get the package - the installer configures ghostscript and other installations really easily. There's good instructions for installing this at Richard Koch's page http://www.uoregon.edu/~koch/texshop/texshop.html along with TexShop. TexShop is quite simply (IMHO) the best way of producing very professional PDFs (with indexing, formulas etc courtessy of LaTex).

[ Reply to This | # ]
Stitching together multiple PDFs with ghostscript
Authored by: shucks on Feb 26, '03 09:34:01PM
I wanted to try other latex methods at first. My ordeal was briefly summarised here. Because of all the problems, I used the ghostscript way instead. But I'm curious about the filesize. Would your way produce smaller filesize?

---
He Travels Far Who Travels Alone, If He Knows The Way That Is

[ Reply to This | # ]

Stitching together multiple PDFs with ghostscript
Authored by: rjbailey on Feb 26, '03 04:53:09PM
I used 'sudo dselect' and selected the GhostScript 6 package. It required a few other packages, and all *binaries* were downloaded and installed without a hitch. Also, I wrote a small script to patch together designated PDF files using this hint. I call it 'pdfpatch' and it looks like this:

#!/bin/sh
gs -sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=output.pdf $*
echo "Patched file is named output.pdf"

I type 'pdfpatch file1.pdf file2.pdf file3.pdf...' from the terminal and it works fine. (The '$*' is the list of pdf files.) I'll also look into running this from OnMyCommand so I won't even have to open a terminal window, e.g. control-click a batch of PDF's from the Finder and select "Patch PDF files".

[ Reply to This | # ]

Stitching together multiple PDFs with ghostscript
Authored by: shucks on Feb 26, '03 09:25:13PM

This is an excellent comment! I was really looking for this. I tried to create a script but it i used $2 (or was it $1) and it failed miserably *DUH*. Can I put your tips on my weblog?

---
He Travels Far Who Travels Alone, If He Knows The Way That Is



[ Reply to This | # ]
cut n pasted...
Authored by: secundar on Feb 26, '03 05:19:14PM
% gs -q -sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=output.pdf *.pdf

I basically cut and pasted from the hint and changed the input file param.

GNU Ghostscript 7.05 (2002-04-22) but i also tried it with Ghostscript 6.01-2

thanks for your help

[ Reply to This | # ]

Worked Great
Authored by: beedee on Feb 27, '03 12:54:30AM

This is a great hint if you have a subscirption to O'Reilly's Safari Bookshelf. For some sections of books, I like to print the printer-friendly version of each page to a PDF, but I end up with like 20 individual PDFs for eacy page... not anymore!

Worked on the first try stitching 20 pdfs into one.



[ Reply to This | # ]
Filled my swap
Authored by: englabenny on Feb 27, '03 10:20:38AM

i ran it on two random pdfs, happening to be two diagrams of 150 kb each. gs bagan to work and the disk of my cube began reading and writing like crazy... when i ^-C:ed gs it had created 4 swapfiles of a total of over 300 MB, and that on a cube with 448 Megs of RAM.



[ Reply to This | # ]
Is there a way with Preview and AppleScript
Authored by: jscotta on Feb 27, '03 02:52:57PM

Ghostscript is nice and the hint works. However, it seems to me that there must be some way to do this using Preview or Preview/AppleScript. I just can't figure out *how* to do it.

Any suggestions anyone?



[ Reply to This | # ]
Is there a way with Preview and AppleScript
Authored by: sbq on May 21, '03 06:09:23PM

I also would like to find an easier way to do this that does not involve Ghostscript (or Acrobat).

-Sam



[ Reply to This | # ]