Thursday, April 07, 2011

Stitch PDF files togather

Many a times I had to face the issue of sending multiple PDF files for official/personal reasons - either by email or for backing up. What bugged me was I had to multiple attachments or references - specially when one had to send a multi-paged invoice or bills - which has been scanned as PDF (each page).

Linux provided a simple solution - using the inbuilt 'Ghostscript' program. Just run it in the command line and presto, we have an output PDF combined file. (ofcourse - you have to have pdfwrite installed - by a simple apt-get install command)


gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=finished.pdf file1.pdf file2.pdf
where:
  • gs -- starts the Ghostscript program
  • -dBATCH -- once Ghostscript processes the PDF files, it should exit. If you don't include this option, Ghostscript will just keep running
  • -dNOPAUSE -- forces Ghostscript to process each page without pausing for user interaction
  • -q -- stops Ghostscript from displaying messages while it works
  • -sDEVICE=pdfwrite -- tells Ghostscript to use its built-in PDF writer to process the files
  • -sOutputFile=finished.pdf -- tells Ghostscript to save the combined PDF file with the name that you specified

No comments:

Post a Comment