Thursday, February 27, 2003

These are the notes and important command lines that we learned today on how to build PDF files from TIFF (or other graphic format) files.

The test stuff is here: /var/www/dev/html/test/x

Here's the command to build the pdf:
htmldoc --header ... --footer ... --webpage --bottom 0 --top 0 --left 0 --right 0 -f jl.pdf a1.html 2> /dev/null

Here's what the HTML file should look like (a1.html in the above line):

<html><head></head><body>
<!-<img src="1/fred.img319.001.gif" width="100%" height="130%">-->
<img src="y.gif" width="100%" height="130%">
</body></html>


Here is our first attempt at trying to convert the tiff to a gif. It works, except that it's inversed:
tifftopnm tiff.tif | ppmquant 256 | ppmtogif > GIF.gif
These programs are all part of the netpbm-progs-9.14-2 package.

HTMLDOC is the groovy package that converts html (and through it gif, jpeg, others) to pdf. It can do it both on Windows and on Linux. A command line version is available.

And this is the magic command line that makes it all work...
X=1/fred.img319.011; tiff2rgba $X x.tif; tifftopnm x.tif | ppmtogif > z.gif ; htmldoc --header ... --footer ... --webpage --bottom 0 --top 0 --left 0 --right 0 -f jl.pdf a1.html

It turns out that the Image Magick package works better than the netpbm stuff for what we need.

So here's a script that converts all of the listed files into one big PDF file using HTMLDOC and ImageMagick. Cool.

#!/bin/sh
######################################################################
# mkpdf: make a pdf out of a bunch of graphic files
######################################################################
DIR=/tmp/mkpdf$$
OUT=$1; shift
if [ -e $OUT ]; then
echo $OUT already exists
exit 1
fi
mkdir $DIR
i=0
FILES=""
while [ -n "$1" ]; do
cat <<DONE >$DIR/$i.html
<html><body><img src="$i.png" width="100%" height="130%"></body></html>
DONE
# tiff2rgba $1 $DIR/x.tif
# tifftopnm $DIR/x.tif | ppmtogif > $DIR/$i.gif
convert $1 $DIR/$i.png
FILES="$FILES $DIR/$i.html"
i=$((i+1));shift
done
htmldoc --header ... --footer ... --webpage --bottom 0 --top 0 --left 0 --right 0 -f $OUT $FILES
rm -rf $DIR


Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?