Created
April 27, 2020 21:33
-
-
Save herpiko/d9636466d93e4955046971a0225f21b7 to your computer and use it in GitHub Desktop.
converting pdf to png, works on multipage PDF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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