I'd like to share a small tool which I created to convert pdf files into single jpgs, which comes very useful especially for great Adama2014's comics.
Since I've got a pretty old machine with small amount of RAM, it's easier to browse through single jpgs than a big pdf file.
The tool is a simple bash script which uses gs and pdfinfo. I figured out it's quite difficult to use pdftk's burst option which fails for many pdf files, so I revetred to the old gs for that.
I remember some folks here use Linux, so I hope you find it useful.
pdf2jpgs
Code: Select all
#!/bin/bash
# extract pages from input pdf file into jpg images
# usage:
# ./script_name input.pdf [density]
# density (optional) is output DPI, 200 by default
# dependencies: pdfinfo, gs, ImageMagick
INP="$1"
DEN="$2"
[[ -z "$2" ]] && DEN=200
NPAGE="$(pdfinfo -- "$INP" 2>/dev/null | grep -i pages | awk '{print $2}')"
DIR="${INP%.*}"
[[ -e "$DIR" ]] && DIR="$(mktemp -du "$DIR"-XXX)"
mkdir -p "$DIR" && cd "$DIR"
echo "images saved in $DIR"
for PAGE in $(seq 1 "$NPAGE"); do
echo "processing page $PAGE"
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -dFirstPage="$PAGE" -dLastPage="$PAGE" -sOutputFile="$PAGE.pdf" ../"$INP" &>/dev/null
convert -density "$DEN" "$PAGE.pdf" "$PAGE.jpg"
rm -f "$PAGE.pdf"
done
Cheers!