View Single Post
Old 03-18-2008, 09:35 AM   #9
axel77
Fanatic
axel77 has learned how to read e-booksaxel77 has learned how to read e-booksaxel77 has learned how to read e-booksaxel77 has learned how to read e-booksaxel77 has learned how to read e-booksaxel77 has learned how to read e-booksaxel77 has learned how to read e-booksaxel77 has learned how to read e-books
 
Posts: 584
Karma: 914
Join Date: Mar 2008
Device: iliad
You are right! convert -adjoin will create an uncompressed pdf, 1.2GB here for a 350 pages book! (beside taking an enternity)

I played a lot the last days to convert a book I scanned, below is the script with which I get a result I'm quite pleased with.

I scanned the book with 300dpi black&white. I don't know if grayscaling would have given better results, that time I thought the iliad works well with black and white, and so I wanted that... Maybe in future one should pick other settings?

I scanned with omnipage and exported the images as uncompressed TIFs so to not have an quality loss. Problem was: the fonts on the scanned images are sometimes only 1 or 2 pixels wide, and when the iLiad zooms this out to fit the screen, it gets quite ugly. So I apply a very small gaussian blur and reconvert everything that has gotten a bit gray to pitch black again, this gets a nice, a bit more fat font that will look cleanly when zoomed.

tiff2ps conveniently takes multiple images to be adjoined to 1 ps file. Strangely enough tiff2pdf cannot do it (one would think there is the same command processor behind these, but oh well). ps2pdf at the last step automatically compresses the images.

The remaining problem I have with is PAPERSIZE in ps2pdf, it defaults to A4, and I set it to A5 because it aprox. matches the pages of this book I'd like to either set the size in pixels, but it takes inches/72 as argument instead, or ideally want it to keep the size of the trimmed images. Dunno how to do that.

The whole script still takes an hour on my 1.2 Ghz notebook for this 350 pages book, but its worth it, as long the result is something you want

Code:
#!/bin/bash 
# parameter: tif files are prefixed with this:
NAME=schone_
# parameter: crop areas (WIDTHxHEIGHT+OffsetLeft+OffsetTop)
CROPLEFT=1800x2200+10+70
CROPRIGHT=1800x2200+1800+70
# this makes the text a bit bolder, so it looks nice when resized on the iliad:
CONVERTOPTS="-trim -blur 1 -threshold 65534"

shopt -s extglob
mkdir tmp

#determine number of pages there..
MAXPAGE=1;
while test -f $NAME*(0)$MAXPAGE.TIF; do let MAXPAGE++; done
let MAXPAGE--

echo "converting $MAXPAGE pages, this will take a while!"

echo "STEP 1 OF 4: preparing left pages"
for ((i = 1; $i <= $MAXPAGE; i++)) do echo "@$i of $MAXPAGE"; convert -crop $CROPLEFT $CONVERTOPTS $NAME*(0)$i.TIF tmp/l$i.TIF; done

echo "STEP 2 OF 4: preparing right pages"
for ((i = 1; $i <= $MAXPAGE; i++)) do echo "@$i of $MAXPAGE"; convert -crop $CROPRIGHT $CONVERTOPTS $NAME*(0)$i.TIF tmp/r$i.TIF; done

echo "STEP 3 OF 4: adjoining pages"
ALL=
for ((i = 1; $i <= $MAXPAGE; i++)) do ALL="$ALL tmp/l$i.TIF tmp/r$i.TIF"; done
tiff2ps $ALL > output.ps

echo "STEP 4 OF 4: converting/compressing to PDF"
ps2pdf -sPAPERSIZE=a5 output.ps
echo "done!"
axel77 is offline   Reply With Quote