Archive for May 9th, 2007
Convert pdf to jpg with GhostScript
So you just downloaded your fresh torrents of comicbooks, magazines, etc and you want to convert each page into jpg. GhostScript comes to the rescue.
Let’s say you have a 100-page simpsons.pdf.
All you do is:
gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=jpeg -r150 -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -dMaxStripSize=8192 -sOutputFile=homer_%d.jpg simpsons.pdf
And you’ll end up with a hundred homer_n.jpg pages of the simpsons.pdf e-book.
That’s it.
ImagMagick’s “convert foo.pdf bar.jpg” will actually do the same thing but if you have a pdf file with non-uniform sized pages convert will actually crop them to it’s default size, undesirably cropping the bigger pages.
*Update: 15 Aug. 2007
Had to use this again. Too long a line to type everytime you need to convert. Better make it into a script and save everybody else the hassle:
$ cat pdf2jpg.sh
#!/bin/bash
if [ $# -ne 2 ];then
echo “Usage: $0 target.pdf outfile”
exit
fi
TARGET=$1
OUTFILE=$2
gs \
-dSAFER \
-dBATCH \
-dNOPAUSE \
-sDEVICE=jpeg \
-r150 \
-dTextAlphaBits=4 \
-dGraphicsAlphaBits=4 \
-dMaxStripSize=8192 \
-sOutputFile=${OUTFILE}_%d.jpg \
${TARGET}





