Skip to content

Instantly share code, notes, and snippets.

@herpiko
Created Apr 27, 2020
Embed
What would you like to do?
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