Skip to content

Instantly share code, notes, and snippets.

@herpiko
Created April 27, 2020 21:33
Show Gist options
  • Save herpiko/d9636466d93e4955046971a0225f21b7 to your computer and use it in GitHub Desktop.
Save herpiko/d9636466d93e4955046971a0225f21b7 to your computer and use it in GitHub Desktop.
converting pdf to png, works on multipage PDF
#!/bin/bash
for file in *; do
if [ ${file: -4} == ".pdf" ]
then
echo "Converting $file using ghost script..."
# Handle multi pages
gs -sstdout=%stderr -dPDFSTOPONERROR -dNOPAUSE -sDEVICE=pngalpha -o $file-%03d.png -r600 $file
if [ "$?" != "0" ]
then
# ghost script may returns error for some PDF files. Use inkscape as failsafe.
echo "Converting $file using inkscape..."
inkscape "$file" -z --export-dpi=600 --export-area-drawing --export-png="$file.png"
fi
fi
done
echo "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment