Return To Message Board
Author Topic:   Batch conversion from multi-page tiff to djvu
Christian Boulanger posted 11/15/03 2:05 AM    
(I first posted this to the archive, please remove there)
Hi everybody,
I was searching the web left and right to find a shell script for batch conversion of multi-page tiffs to multi-page djvu. After not finding anything I wrote my first (!) bash script and post it here for improvement by the More Able. This one runs REALLY slow (But works).
#!/bin/sh
#
# convert all multi-page tiffs in a directory to a multi-page dvju
#
# Author: c period boulanger at gmx period de, Nov 15, 2003, late at night
#
# requires:
# - netbpm installed (tifftopnm suffices)
# - dvju-libre installed
# - tiffsplit
# tiffsplit, tifftopnm, cjb2, djvm in the PATH
#
# Please improve!!
mkdir tmp
for i in *.tif; do
echo "Now converting $i... "
cp $i tmp/$i
cd tmp
tiffsplit $i
rm $i
for j in *.tif; do
tifftopnm $j > $j.pnm
cjb2 -dpi 150 -clean -loose $j.pnm $j.djvu
rm $j
rm $j.pnm
done
djvm -c temp.djvu *.djvu
cd ..
mv tmp/temp.djvu $i.djvu
rm tmp/*.*
done
rmdir tmp
What I would really love to see is a PHP extension for djvu. Has anyone ever started such a project?
Cheers, Christian



http://www.panyasan.de
Christian Boulanger posted 11/15/03 11:16 AM    
... it takes several minutes to convert a 20-page, 300dpi scanned tiff-file. For larger tasks, this is obviously quite tedious. As I understand, the only way to avoid that is to buy the commercial Lizardtech stuff. Isn't there any binary that would do the direct tiff-djvu conversion?
Cheers, Christian
James Rile posted 11/15/03 5:09 PM     Click here to send email to James Rile  
DjVu Solo 3.1 (link on PlanetDjVu home page) can do it.


http://www.planetdjvu.com
The Global Forum for DjVu
Christian Boulanger posted 11/15/03 5:26 PM    
James,
thanks for your reply.
Can it do *batch* conversion, I mean, can I use it as a command line tool, or have it convert a whole directory of .tifs automatically?
Christian
James Rile posted 11/15/03 5:34 PM     Click here to send email to James Rile  
Hi Christian,
No, not as a batch tool or as a command line tool. Just one at a time conversion. The same for the on-line Any2djVu conversion server. But both are free.
Look in the coming days here for a posting of new lower prices for LizardTech DjVu encoders, and a DjVu encoding product from me, called JRAPublish.
Jim


http://www.planetdjvu.com
The Global Forum for DjVu
Christian Boulanger posted 11/15/03 9:18 PM    
James,
I'll be looking. For the time being, here is a slightly improved script to do the trick. For those with lots of time and little money.
Best, Christian
#!/bin/sh
# tiff2dvju.sh
#
# converts all multi-page tiff-files in a directory to multi-page dvju-files
#
# Author: c dot boulanger at gmx dot de
#
# requires:
# - tiffsplit (libtif pkg),
# - tifftopnm (netpbm or tetex pkg),
# - cjb2, djvm (djvu-libre pkg)
# - all binaries must be in directories in the PATH
# - write priviledges for the script
# Improvements welcome!
# This is my first shell script, this is fun!
echo "This will convert all .tif documents in this folder to .djvu-Files"
echo "Type 'y' if you want to delete the source files afterwards."
echo -n ">"
read a
mkdir tmp
for i in *.tif; do
echo -n "Now converting $i. Please wait. Pages left: "
cp $i tmp/$i # make a copy of source file in temp file
cd tmp
tiffsplit $i 2>null # split tif into individual pages and suppress stderr
rm $i # delete multipage file
n=`ls | wc -l` # number of files
p=0 # reset counter
for j in *.tif; do
p=`expr $p + 1` # increment counter
l=`expr $n - $p` # number of pages left
if [ $l -lt 10 ]; then l=" $l"; fi # add leading space
echo -e "$l\b\b\\c" # output to be overwritten
tifftopnm $j > $j.pnm 2> null # convert tif to pnm format, suppress stderr
cjb2 -dpi 150 -clean -loose $j.pnm $j.djvu # convert pnm to djvu
rm $j; rm $j.pnm # delete tif and pnm
done
djvm -c temp.djvu *.djvu # merge djvu files
cd ..
n=`echo $i | sed 's/\(.*\.\)tif/\1djvu/'` # replace .tif extension with .djvu extension
mv tmp/temp.djvu $n # retrieve merged file
rm tmp/*.* # delete all temp files
echo # output result
echo -n " Source file: `ls -sh $i`" # show size of source file
if [ $a ]; # delete source file if requested
then rm $i; echo " ...deleted."
else echo
fi
echo " Dest. file: `ls -sh $n`" # show size of target file
done
rmdir tmp
James Rile posted 11/15/03 11:52 PM     Click here to send email to James Rile  
That's Great Christian,
We have these compiled DjVuLibre and other open-source compiled binaries for Windows, but they are not very useful without a batch script like this.
Why don't you zip it all up and we can offer a download link here at PlanetDjVu? Just email me the zipped or rarred file, or host it yourself and send me the URL.
- Jim
P.S. The next step (after this script is polished) will be for someone to create a VB application that uses these binaries (generates .bat files).



http://www.planetdjvu.com
The Global Forum for DjVu
Christian Boulanger posted 11/17/03 8:53 AM    
Hi James,
glad you find the script useful. I am more than happy to provide it for use and improvement by the dvju community. I am running it on Windows with Cygwin. What files would you like me to zip up - the individual binaries used by the script? Do they function by themselves, without the package they come with, and without cygwin running?
I have just started learning linux shell script programming, I don't know anything about Windows shell scripts. I am sure someone could quickly translate, or even write a VB application - would they be able to use the cygwin binaries? I have not much experience with those porting issues.
Christian
Christian posted 11/21/03 11:46 PM    
Last post on this topic: I have put the script here:
http://www.panya.de/snippets/tiff2djvu.htm
and will update it if someone improves it. It works well now if you can put up with letting your computer run for hours and days.
Best,
Christian
Return To Message Board

PlanetDjVu  | Post New Topic