Skip to content

Instantly share code, notes, and snippets.

@stevekm
Last active June 29, 2023 01:13
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save stevekm/0f893ef09e9dea6dac220b3be5289ffe to your computer and use it in GitHub Desktop.
Save stevekm/0f893ef09e9dea6dac220b3be5289ffe to your computer and use it in GitHub Desktop.
Commands to convert multi-page PDF to/from multiple PNG files with GhostScript & ImageMagick
  • Convert multipage PDF into single page PNG files with GhostScript

http://superuser.com/questions/350201/convert-many-images-to-one-pdf-on-mac/854606?noredirect=1#comment1639104_854606

gs -o /path/to/output_page_%03d.png -sDEVICE=png16m -r150 /path/to/input.pdf
  • Convert multiple single-page PDF files into one multi-page PDF file
FILES="$(find /path/to/dir/ -type f -name "*.pdf" | sort)"
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=merged_output.pdf $FILES
  • Convert multiple PNG files into single multi-page PDF with ImageMagick

http://stackoverflow.com/questions/11002982/converting-multi-page-pdfs-to-several-jpgs-using-imagemagick-and-or-ghostscript?rq=1

convert "*.png" output.pdf

Tested with OS X 10.11 El Capitan, commands should work on most any OS that can run these programs

@nikhilCad
Copy link

Thank you for saving my life with this!

@ngekoding
Copy link

Can we define the PDF version result with convert "*.png" output.pdf?

I try and get PDF version 1.7, but I want 1.4, can I do that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment