Memo-migrated‎ > ‎

Merge PDFs via ghostscript

posted Sep 16, 2017, 12:24 PM by Teng-Yok Lee   [ updated Jan 2, 2021, 7:06 PM ]

REF: stackoverflow

Install ghostscript (www). For windows, download and execute the installer.

Open a command prompt and set the path so it can find the executable. For instance,

$ set PATH="C:\Program Files\gs\gs9.20\bin";%PATH%


Run the following command to merge pdfs.
$ gswin64c ^
-dBATCH ^
-dNOPAUSE ^
-sPAPERSIZE=letter ^
-sDEVICE=pdfwrite ^
-dPDFSETTINGS=/prepress ^
-dCompatibilityLevel=1.4 ^
-dAutoFilterColorImages=false ^
-dAutoFilterGrayImages=false ^
-dColorImageFilter=/LZW ^
-dGrayImageFilter=/LZW ^
-dMonoImageFilter=/LZW ^
-dDownsampleGrayImages=false ^
-dDownsampleColorImages=false ^
-dSubsetFonts=true ^
-dEmbedAllFonts=true ^
-sOutputFile=output.pdf.pdf ^
1.pdf 2.pdf

NOTES:
  • Capacity 1.4 is needed for images with semi-transparency. Otherwise, the pages with semi-transparent figures might be rastered into images (REF).
  • I am using the command gswin64c.exe so the output can be displayed in the same command prompt. Another command gswin64.exe will create another window.
  • I use LZW to losslessly compress the images.
  • All fonts will be embedded to that pdf (REF: earlier notes about ps2pdf options: http://www.recheliu.org/memo/generatepdfforieeetvcg).

Comments