Linux: pdfs into single jpgs, good for Adama2014's comics

Found an interesting gallery online or added some new images to FembotWiki? Post photo-manipulations, artwork, or other visual media here.
Post Reply
User avatar
Chemik
Posts: 199
Joined: Sat Mar 12, 2005 8:37 pm
Technosexuality: Built and Transformation
Identification: Human
Gender: Male
x 2
Contact:

Linux: pdfs into single jpgs, good for Adama2014's comics

Post by Chemik » Sat Aug 29, 2015 2:08 pm

Hello Linux folks,

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
Of course you should chmod the script and so on, but you know it if you use Linux.

Cheers!
Last edited by Chemik on Mon Aug 31, 2015 7:21 am, edited 2 times in total.

User avatar
Silkscreen
Alternate account
Posts: 162
Joined: Thu Jan 22, 2015 12:25 pm
Technosexuality: Transformation
Identification: Cyborg
Gender: Female
x 1
Contact:

Re: Linux: pdfs into single jpgs, good for Adama2014's comic

Post by Silkscreen » Sat Aug 29, 2015 2:36 pm

Fails for my brochure with

Code: Select all

Unrecoverable error: rangecheck in .putdeviceprops
convert: no images defined `1.jpg' @ error/convert.c/ConvertImageCommand/3187.

User avatar
Chemik
Posts: 199
Joined: Sat Mar 12, 2005 8:37 pm
Technosexuality: Built and Transformation
Identification: Human
Gender: Male
x 2
Contact:

Re: Linux: pdfs into single jpgs, good for Adama2014's comic

Post by Chemik » Sat Aug 29, 2015 3:55 pm

Silkscreen wrote:Fails for my brochure with

Code: Select all

Unrecoverable error: rangecheck in .putdeviceprops
convert: no images defined `1.jpg' @ error/convert.c/ConvertImageCommand/3187.
Silkscreen, I tested the script on your brochure (really great piece, btw.) and it worked all-right (Fedora 20), your problem might be related to gs.

Post Reply
Users browsing this forum: No registered users and 21 guests