#!/bin/sh
# Copyright (C) 2008 Adalbert Prokop, adalbert.prokop(%)web.de
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
#set -x # debug
declare -i WIDTH
declare -i HEIGHT
declare -i RPS # rows per strip, multiple of 16 for JPEG
RPS=16
DEBUG=
AUTHOR=
ALIGN=center
VALIGN=middle
CREATOR=
DATE=$(date +%Y%m%d%H%M%S)
KEYWORDS=
PAPER=A4
PWIDTH=21.0
PHEIGHT=29.7
QUALITY=85
SUBJECT=
TITLE=
WORKAROUND=no
function showhelp() {
cat <
Autor for the PDF file.
-c|--creator
Creator for the PDF file.
-d|--date YYYYMMDDHHMMSS
Date for the PDF file. Defaults to now.
-k|--keywords
Keywords for the PDF file.
-s|--subject
Subject for the PDF file.
-t|--title
Title for the PDF file.
-p|--paper [A4|A5]
Papersize.
-q|--quality [0..100]
JPEG compression quality. Defaults to $QUALITY.
EOF
}
if [ $# -eq 0 ]; then
showhelp
exit 0
fi
if [ -z "$(which python 2>/dev/null)" ]; then
cat < 0.1") == "True" ]; then
echo "*** Resolution ratio of $file is NOT DIN norm! ***"
fi
XRES=$(python -c "print '%.2f' % ($WIDTH/$PWIDTH)")
YRES=$(python -c "print '%.2f' % ($HEIGHT/$PHEIGHT)")
RES=$(python -c "print($XRES if $XRES > $YRES else $YRES)")
[ "$DEBUG" ] && echo "pamtotiff -rowsperstrip=$RPS -truecolor -xresolution=$RES -yresolution=$RES -resolutionunit=centimeter $file > ${file%.pnm}.tif"
echo -n "Converting $file (${RES}dpcm) to TIFF format... "
pamtotiff -rowsperstrip=$RPS -truecolor -xresolution=$RES -yresolution=$RES -resolutionunit=centimeter "$file" > "${file%.pnm}.tif" && echo "done." || echo "failed."
done
[ "$DEBUG" ] && echo "tiffcp -r $RPS $dir/*.tif $dir.tif"
echo -n "Creating combined TIFF... "
tiffcp -r $RPS "$dir"/*.tif "$dir.tif" && rm -f "$dir"/*.tif && echo "done." || echo "failed."
[ "$DEBUG" ] && echo "tiff2pdf -o $dir.pdf -j -q $QUALITY -p $PAPER $dir.tif"
echo -n "Creating PDF from combined TIFF image... "
tiff2pdf -o "$dir.pdf" -j -q $QUALITY -p $PAPER -f \
${TITLE:+-t"$TITLE"} \
${AUTHOR:+-a"$AUTHOR"} \
${CREATOR:+-c"$CREATOR"} \
${SUBJECT:+-s"$SUBJECT"} \
${KEYWORDS:+-k"$KEYWORDS"} \
${DATE:+-e"$DATE"} \
"$dir.tif" && rm -f "$dir.tif" && echo "done." || echo "failed."
if [ "$WORKAROUND" = "yes" ]; then
echo "Applying workaround."
sed -e 's#/ColorTransform 0#/ColorTransform 1#g' "$dir.pdf" > "$dir.pdf.tmp"
mv -f "$dir.pdf.tmp" "$dir.pdf"
fi
done