update makebook
This commit is contained in:
parent
affb7e9935
commit
5a77c03eaf
101
bin/makebook
101
bin/makebook
@ -6,10 +6,10 @@
|
||||
#
|
||||
#**********************************************************#
|
||||
# makebook #
|
||||
# written by Donald P. Goodman III #
|
||||
# Copyright (C) 2011 #
|
||||
# #
|
||||
# Impose pdf pages for binding #
|
||||
# written by Donald P. Goodman III #
|
||||
# Copyright (C) 2011 #
|
||||
# #
|
||||
# Impose pdf pages for binding #
|
||||
#**********************************************************#
|
||||
#
|
||||
# This program is free software: you can redistribute it
|
||||
@ -30,9 +30,11 @@
|
||||
#**********************************************************#
|
||||
# begin the code #
|
||||
#**********************************************************#
|
||||
# make script more portable and secure
|
||||
PATH=/bin:/usr/bin:/usr/local/bin ; export PATH
|
||||
umask 033
|
||||
# define our revision number variable for rcs
|
||||
REVISION="2.0"
|
||||
REVISION="2.1"
|
||||
# define error codes
|
||||
E_WRONG_ARGS=64 # too many or few args
|
||||
E_BAD_SIG_TYPE=65 # invalid type of signature
|
||||
@ -74,6 +76,14 @@ command -v pdftk >/dev/null 2>&1 ||
|
||||
{ echo >&2 "makebook: error: requires pdftk, but it's not installed";
|
||||
exit $E_NO_PROG;
|
||||
}
|
||||
command -v dc >/dev/null 2>&1 ||
|
||||
{ echo >&2 "makebook: error: requires dc, but it's not installed";
|
||||
exit $E_NO_PROG;
|
||||
}
|
||||
command -v bc >/dev/null 2>&1 ||
|
||||
{ echo >&2 "makebook: error: requires bc, but it's not installed";
|
||||
exit $E_NO_PROG;
|
||||
}
|
||||
|
||||
# print the version information and exit successfully
|
||||
versionfunc ()
|
||||
@ -122,7 +132,7 @@ End-of-help
|
||||
# define a for dealing with units; convert to bp ()
|
||||
unitarg ()
|
||||
{
|
||||
if [ ! `echo "$1" | grep '^[\+\|-]*[0-9\.][0-9\.]*\(in\|cm\|pt\|bp\|pc\|$\)'` ]
|
||||
if [ ! `echo "$1" | grep '^[\+\|-]*[0-9\.][0-9\.]*\(in\|cm\|pt\|mm\|bp\|pc\|$\)'` ]
|
||||
then
|
||||
echo "ERROR: dimension \"$1\" not valid." >&2
|
||||
exit $E_BAD_UNIT
|
||||
@ -135,6 +145,10 @@ unitarg ()
|
||||
then
|
||||
OPTARG=`echo "scale=0; ${1%cm} * 28.3464567" | bc`
|
||||
OPTARG=${OPTARG%.*}
|
||||
elif [ `expr match "$1" '.*\(mm\)'` ]
|
||||
then
|
||||
OPTARG=`echo "scale=0; ${1%mm} * 2.83464567" | bc`
|
||||
OPTARG=${OPTARG%.*}
|
||||
elif [ `expr match "$1" '.*\(pt\)'` ]
|
||||
then
|
||||
OPTARG=`echo "scale=0; ${1%pt} / 1.00375" | bc`
|
||||
@ -276,7 +290,7 @@ NUM_PAGES=`pdfinfo "$NEW_FILE_NAME" | awk '/Pages:/ {print $2}'`;
|
||||
SRC_PAGE_WIDTH=`pdfinfo "$NEW_FILE_NAME" | awk '/Page\ size:/ {print $3}'`;
|
||||
SRC_PAGE_HEIGHT=`pdfinfo "$NEW_FILE_NAME" | awk '/Page\ size:/ {print $5}'`;
|
||||
# find the number of pages we'll have per signature
|
||||
PAGES_PER_SIG=$(($PAGES_PER_SIG * $SECT_TYPE))
|
||||
PAGES_PER_SIG=$(dc -e "$PAGES_PER_SIG $SECT_TYPE * p")
|
||||
# determine if extra pages will be necessary
|
||||
NUM_BLANKS=`expr $NUM_PAGES % $PAGES_PER_SIG`
|
||||
if [ $NUM_BLANKS -ne 0 ]
|
||||
@ -292,14 +306,13 @@ then
|
||||
echo "\documentclass{article}" > blank.tex
|
||||
echo '\\thispagestyle{empty}' >> blank.tex
|
||||
echo "\usepackage[paperwidth=${SRC_PAGE_WIDTH}bp,paperheight="${SRC_PAGE_HEIGHT}bp"]{geometry}" >> blank.tex
|
||||
echo '\\begin{document}' >> blank.tex
|
||||
echo "\quad \end{document}" >> blank.tex
|
||||
echo '\\begin{document}' >> blank.tex
|
||||
echo "\quad \\\\end{document}" >> blank.tex
|
||||
if [ $VERBOSE -eq 1 ]
|
||||
then
|
||||
echo "CREATING blank page to fill sections...";
|
||||
fi
|
||||
pdflatex blank.tex > /dev/null 2&>1
|
||||
rm blank.aux blank.log blank.tex
|
||||
fi
|
||||
# now insert blank pages as needed, preferring the back for
|
||||
# odd numbers by default, front if stated
|
||||
@ -362,7 +375,7 @@ tmp=`expr $NUM_PAGES + $NUM_BLANKS`
|
||||
if [ $VERBOSE -eq 1 ]
|
||||
then
|
||||
echo "IMPOSING $NUM_PAGES pages ($tmp with blanks) on
|
||||
$(($NUM_SIGS * $SECT_TYPE)) signature(s) gathered in
|
||||
$(dc -e "$NUM_SIGS $SECT_TYPE * p") signature(s) gathered in
|
||||
sections of $SECT_TYPE signature(s) each...";
|
||||
fi
|
||||
# arrange the pages for impression on signatures
|
||||
@ -377,16 +390,16 @@ do
|
||||
if [ "$SIG_TYPE" = "quarto" ]
|
||||
then
|
||||
# determine size of target page
|
||||
if [ $(echo "$TGT_PAGE_HEIGHT == 0" | bc) -eq 1 ]
|
||||
if [ $TGT_PAGE_HEIGHT -eq 0 ]
|
||||
then
|
||||
TGT_PAGE_HEIGHT=$(echo "$SRC_PAGE_HEIGHT * 2" | bc)
|
||||
TGT_PAGE_HEIGHT=$(dc -e "$SRC_PAGE_HEIGHT 2 * p")
|
||||
fi
|
||||
if [ $(echo "$TGT_PAGE_WIDTH == 0" | bc) -eq 1 ]
|
||||
if [ $TGT_PAGE_WIDTH -eq 0 ]
|
||||
then
|
||||
TGT_PAGE_WIDTH=$(echo "$SRC_PAGE_WIDTH * 2" | bc)
|
||||
TGT_PAGE_WIDTH=$(dc -e "$SRC_PAGE_WIDTH 2 * p")
|
||||
fi
|
||||
# do the rearranging
|
||||
k=$i; n=1; total=$(($SECT_TYPE * 8)); m=$total
|
||||
k=$i; n=1; total=$(dc -e "$SECT_TYPE 8 * p"); m=$total
|
||||
while [ $n -le $SECT_TYPE ]
|
||||
do
|
||||
pdftk "$NEW_FILE_NAME" cat `expr $k + $m - 1` $k \
|
||||
@ -418,16 +431,16 @@ do
|
||||
elif [ "$SIG_TYPE" = "folio" ]
|
||||
then
|
||||
# determine size of target page
|
||||
if [ $(echo "$TGT_PAGE_HEIGHT == 0" | bc) -eq 1 ]
|
||||
if [ 1 -eq "$(echo "${TGT_PAGE_HEIGHT} == 0" | bc)" ]
|
||||
then
|
||||
TGT_PAGE_HEIGHT=$(echo "$SRC_PAGE_HEIGHT * 1" | bc)
|
||||
TGT_PAGE_HEIGHT=$(dc -e "$SRC_PAGE_HEIGHT 1 * p")
|
||||
fi
|
||||
if [ $(echo "$TGT_PAGE_WIDTH == 0" | bc) -eq 1 ]
|
||||
if [ 1 -eq "$(echo "${TGT_PAGE_WIDTH} == 0" | bc)" ]
|
||||
then
|
||||
TGT_PAGE_WIDTH=$(echo "$SRC_PAGE_WIDTH * 2" | bc)
|
||||
TGT_PAGE_WIDTH=$(dc -e "$SRC_PAGE_WIDTH 2 * p")
|
||||
fi
|
||||
# do the rearranging
|
||||
k=$i; n=1; total=$(($SECT_TYPE * 4)); m=$total
|
||||
k=$i; n=1; total=$(dc -e "$SECT_TYPE 4 * p"); m=$total
|
||||
while [ $n -le $SECT_TYPE ]
|
||||
do
|
||||
pdftk "$NEW_FILE_NAME" cat `expr $k + $m - 1` \
|
||||
@ -458,16 +471,16 @@ do
|
||||
elif [ "$SIG_TYPE" = "octavo" ]
|
||||
then
|
||||
# determine target page dimensions
|
||||
if [ $(echo "$TGT_PAGE_HEIGHT == 0" | bc) -eq 1 ]
|
||||
if [ 1 -eq "$(echo "${TGT_PAGE_HEIGHT} == 0" | bc)" ]
|
||||
then
|
||||
TGT_PAGE_HEIGHT=$(echo "$SRC_PAGE_HEIGHT * 2" | bc)
|
||||
TGT_PAGE_HEIGHT=$(dc -e "$SRC_PAGE_HEIGHT 2 * p")
|
||||
fi
|
||||
if [ $(echo "$TGT_PAGE_WIDTH == 0" | bc) -eq 1 ]
|
||||
if [ 1 -eq "$(echo "${TGT_PAGE_WIDTH} == 0" | bc)" ]
|
||||
then
|
||||
TGT_PAGE_WIDTH=$(echo "$SRC_PAGE_WIDTH * 4" | bc)
|
||||
TGT_PAGE_WIDTH=$(dc -e "$SRC_PAGE_WIDTH 4 * p")
|
||||
fi
|
||||
# do the rearranging
|
||||
k=$i; n=1; total=$(($SECT_TYPE * 16)); m=$total
|
||||
k=$i; n=1; total=$(dc -e "$SECT_TYPE 16 * p"); m=$total
|
||||
while [ $n -le $SECT_TYPE ]
|
||||
do
|
||||
pdftk "$NEW_FILE_NAME" cat `expr $k + 3` \
|
||||
@ -503,16 +516,16 @@ do
|
||||
elif [ "$SIG_TYPE" = "sexto" ]
|
||||
then
|
||||
# determine target page dimensions
|
||||
if [ $(echo "$TGT_PAGE_HEIGHT == 0" | bc) -eq 1 ]
|
||||
if [ $TGT_PAGE_HEIGHT -eq 0 ]
|
||||
then
|
||||
TGT_PAGE_HEIGHT=$(echo "$SRC_PAGE_HEIGHT * 3" | bc)
|
||||
TGT_PAGE_HEIGHT=$(dc -e "$SRC_PAGE_HEIGHT 3 * p")
|
||||
fi
|
||||
if [ $(echo "$TGT_PAGE_WIDTH == 0" | bc) -eq 1 ]
|
||||
if [ $TGT_PAGE_WIDTH -eq 0 ]
|
||||
then
|
||||
TGT_PAGE_WIDTH=$(echo "$SRC_PAGE_WIDTH * 2" | bc)
|
||||
TGT_PAGE_WIDTH=$(dc -e "$SRC_PAGE_WIDTH 2 * p")
|
||||
fi
|
||||
# do the rearranging
|
||||
k=$i; n=1; total=$(($SECT_TYPE * 12)); m=$total
|
||||
k=$i; n=1; total=$(dc -e "$SECT_TYPE 12 * p"); m=$total
|
||||
while [ $n -le $SECT_TYPE ]
|
||||
do
|
||||
pdftk "$NEW_FILE_NAME" cat `expr $k + 5` \
|
||||
@ -547,16 +560,16 @@ do
|
||||
elif [ "$SIG_TYPE" = "duodecimo" ]
|
||||
then
|
||||
# determine target page dimensions
|
||||
if [ $(echo "$TGT_PAGE_HEIGHT == 0" | bc) -eq 1 ]
|
||||
if [ $TGT_PAGE_HEIGHT -eq 0 ]
|
||||
then
|
||||
TGT_PAGE_HEIGHT=$(($SRC_PAGE_HEIGHT * 3))
|
||||
TGT_PAGE_HEIGHT=$(dc -e "$SRC_PAGE_HEIGHT 3 * p")
|
||||
fi
|
||||
if [ $(echo "$TGT_PAGE_WIDTH == 0" | bc) -eq 1 ]
|
||||
if [ $TGT_PAGE_WIDTH -eq 0 ]
|
||||
then
|
||||
TGT_PAGE_WIDTH=$(($SRC_PAGE_WIDTH * 4))
|
||||
TGT_PAGE_WIDTH=$(dc -e "$SRC_PAGE_WIDTH 4 * p")
|
||||
fi
|
||||
# do the rearranging
|
||||
k=$i; n=1; total=$(($SECT_TYPE * 24)); m=$total
|
||||
k=$i; n=1; total=$(dc -e "$SECT_TYPE 24 * p"); m=$total
|
||||
while [ $n -le $SECT_TYPE ]
|
||||
do
|
||||
pdftk "$NEW_FILE_NAME" cat `expr $k + 8` \
|
||||
@ -605,22 +618,32 @@ echo '\\begin{document}' >> ${OUTFILE_NAME%.pdf}.tex
|
||||
echo "\includepdf[nup=$NUP,pages=-,turn=false,columnstrict,
|
||||
noautoscale,delta=${HORIZ_DELTA}bp ${VERT_DELTA}bp,
|
||||
offset=${HORIZ_OFFSET}bp ${VERT_OFFSET}bp,scale=${SCALE}]
|
||||
{./"$NEW_FILE_NAME"}\end{document}" >> ${OUTFILE_NAME%.pdf}.tex
|
||||
{./"$NEW_FILE_NAME"}" >> ${OUTFILE_NAME%.pdf}.tex
|
||||
echo "\\\\end{document}" >> ${OUTFILE_NAME%.pdf}.tex
|
||||
if [ $VERBOSE -eq 1 ]
|
||||
then
|
||||
echo "IMPOSING sections..."
|
||||
fi
|
||||
pdflatex ${OUTFILE_NAME%.pdf}.tex #> /dev/null 2>&1
|
||||
pdflatex ${OUTFILE_NAME%.pdf}.tex > /dev/null 2>&1
|
||||
if [ $VERBOSE -eq 1 ]
|
||||
then
|
||||
echo "CLEANING up..."
|
||||
fi
|
||||
rm ${OUTFILE_NAME%.pdf}.tex ${OUTFILE_NAME%.pdf}.aux \
|
||||
${OUTFILE_NAME%.pdf}.log "$NEW_FILE_NAME"
|
||||
if [ -e "./blank.tex" ]; then
|
||||
rm ./blank.tex
|
||||
fi
|
||||
if [ -e "./blank.aux" ]; then
|
||||
rm ./blank.aux
|
||||
fi
|
||||
if [ -e "./blank.log" ]; then
|
||||
rm ./blank.log
|
||||
fi
|
||||
if [ $VERBOSE -eq 1 ]
|
||||
then
|
||||
echo "`expr $NUM_PAGES + $NUM_BLANKS` pages imposed in
|
||||
$(($NUM_SIGS * $SECT_TYPE)) $SIG_TYPE signatures gathered
|
||||
$(dc -e "$NUM_SIGS $SECT_TYPE * p") $SIG_TYPE signatures gathered
|
||||
in sections of $SECT_TYPE signature(s) each and output to
|
||||
${OUTFILE_NAME%.pdf}.pdf."
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user