Created
November 10, 2010 15:18
-
-
Save yura/670974 to your computer and use it in GitHub Desktop.
script to PDF to JPG using pdftk and imagemagick
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 | |
# Script to convert PDF file to JPG images | |
# | |
# Dependencies: | |
# * pdftk | |
# * imagemagick | |
PDF=$1 | |
echo "Processing $PDF" | |
DIR=`basename "$1" .pdf` | |
mkdir "$DIR" | |
echo ' Splitting PDF file to pages...' | |
pdftk "$PDF" burst output "$DIR"/%04d.pdf | |
pdftk "$PDF" dump_data output "$DIR"/metadata.txt | |
echo ' Converting pages to JPEG files...' | |
for i in "$DIR"/*.pdf; do | |
convert -colorspace RGB -interlace none -density 300x300 -quality 100 "$i" "$DIR"/`basename "$i" .pdf`.jpg | |
done | |
echo 'All done' |
Thanks a lot for your work! I've ported this script to Windows, here you can find my gist https://gist.github.com/agurz/7c72653bf1923804f26b8c0211de4669
Hin: you need to have ghostscript installed for this as imagemagick relies on it. If it's missing you might see an error like
convert: FailedToExecuteCommand `'gs' -sstdout=%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 '-sDEVICE=pngalpha' -dTextAlphaBits=4 -dGraphicsAlphaBits=4 '-r300x300' '-sOutputFile=/var/folders/w_/bn46lxks695dg9yvvrgx_xnm0000gn/T/magick-23598b4Fr54IpZ4vE%d' '-f/var/folders/w_/bn46lxks695dg9yvvrgx_xnm0000gn/T/magick-23598hwvO5gF963Ot' '-f/var/folders/w_/bn46lxks695dg9yvvrgx_xnm0000gn/T/magick-23598JknpjTH6yPWj'' (1) @ error/pdf.c/InvokePDFDelegate/291.
convert: no images defined `0002.jpg' @ error/convert.c/ConvertImageCommand/3275. ```
Thanks a lot for the script!
thanks man, really usefull!
Hin: you need to have ghostscript installed for this as imagemagick relies on it. If it's missing you might see an error like
convert: FailedToExecuteCommand `'gs' -sstdout=%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 '-sDEVICE=pngalpha' -dTextAlphaBits=4 -dGraphicsAlphaBits=4 '-r300x300' '-sOutputFile=/var/folders/w_/bn46lxks695dg9yvvrgx_xnm0000gn/T/magick-23598b4Fr54IpZ4vE%d' '-f/var/folders/w_/bn46lxks695dg9yvvrgx_xnm0000gn/T/magick-23598hwvO5gF963Ot' '-f/var/folders/w_/bn46lxks695dg9yvvrgx_xnm0000gn/T/magick-23598JknpjTH6yPWj'' (1) @ error/pdf.c/InvokePDFDelegate/291. convert: no images defined `0002.jpg' @ error/convert.c/ConvertImageCommand/3275. ``` Thanks a lot for the script!
Thanks for clearing that up!
Very Nice. Thanks
Simpler solution is to just use pdftoppm
:
pdftoppm -jpeg {pdf file} {output folder}
Install with sudo apt install poppler-utils
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot for this!