Jed’s fridge door notes (a.k.a. “so i won’t forget”)

classic jazz, unix one-liners, anti-theism, crypto

Archive for May 9th, 2007

Convert pdf to jpg with GhostScript

with 20 comments

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}

Written by jedrm

May 9, 2007 at 3:36 pm

Posted in Unix One-Liners

Tagged with , , ,