© copyright 02.Jan.2009 by Paul Bradley filed under PDF
I am in the process of developing a large document management system, where each document within the system is published to a PDF file for viewing and printing. One of the requirements of the system is that certain sub categories of documents need all the individual PDF files to be merged together into a logical sequence to create a master "overview" PDF file.
A quick search on Google lists a whole array of tools that can do this, but I needed something that could be run from the command line, so that my program can call this external utility to combine the PDF files in the order that I stipulate. I had used Ghostscript on a previous project to convert Postscript files to PDF files, but hadn't realised how easy was to merge PDF files using Ghostscript.
The example below will combine the files 1.pdf, 2.pdf and 3.pdf into a new PDF file called merged.pdf
gswin32 -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUT=merged.pdf
-dBATCH 1.pdf 2.pdf 3.pdf
n.b. the code should be typed on one line, split here for presentation.
About the Author
Paul Bradley is a VB.NET software developer living and working in Cumbria. He provides PHP & MySQL bespoke development services via his software development company, Carlisle Software Limited.
He has over 20 years programming experience.