Nov 18

Merging multiple pdf files and jpg files into one PDF

Category: Linux   — Published by tengo on November 18, 2011 at 10:59 am

As shown in Merging two or more PDFs into one, combining pdf files is simple with gs (ghostscript):

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=finished.pdf inputfile1.pdf inputfile2.pdf

I should be equally simple if you've got some JPG files among the files you want to merge, through gs input filters, but I couldn't get it to work. That's why I use a little detour over gimp:

1. Open all JPG files in Gimp and save them as .ps (PostScript files)
2. Then use these .ps files in your gs command, mixing them with pdf files

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=finished.pdf inputfile1.ps inputfile2.pdf

Note:
Gimp is also handy when you've got bloated pdf files with embedded images. Open the pdfs in Gimp, separate the layers you've want to keep, or size-down the images and save your result als .ps or .jpg

Related

Combining two or more PDFs into one, on Linux
Extract images from PDF files
Convert images to PDF document, on Linux, on CLI