#!/bin/bash ######################################################################## # # Program: booklet-print # # Author: Conor Daly # Version: 0.1.1 # Date: 03 Oct 2002 # # License: GPL # # Purpose: # formats a document for printing in A5 booklet form. # # uses the HP colour printer # # takes input from stdin or as a file # # we'll do nothing fancy here, just take the file and stuff it # through psbook and mpage and hand it to the printer # # Bugs: Completely ignores any of the usual print accounting stuff # that comes in from lpr. # ######################################################################### # Set the print queue to use. It must be capable of duplex printing or # you won't get sensible output PRINTER=xcolour #PRINTER=pcolour PRINTER_COMMAND="lpr -P${PRINTER}" # For debug info, uncomment the "LOGFILE=" line below LOGFILE=/var/spool/lpd/booklet/log # Start the print run... [ $LOGFILE ] && echo >> $LOGFILE [ $LOGFILE ] && echo "________________________________________________" >> $LOGFILE [ $LOGFILE ] && echo -n "Starting print run at: " >> $LOGFILE [ $LOGFILE ] && date >> $LOGFILE [ $LOGFILE ] && echo $0 $* >> $LOGFILE # pipe or console? if [ -t 0 ]; then # We're in a console here [ $LOGFILE ] && echo "console">> $LOGFILE FILE=$1 PIPE= else # Here, we're in a pipe # We need a temporary file here so something else can carry on [ $LOGFILE ] && echo "pipe">> $LOGFILE FILE=/tmp/booklet-print$$.tmp cat > $FILE PIPE=1 fi # Find out how many pages to print NUM=`mpage -1 $FILE | grep %%Pages: | tail -1 | cut -f2 -d" "` [ $LOGFILE ] && echo "Processing ${NUM} pages from ${FILE}..." >> $LOGFILE # We need an exact multiple of 4 for psbook ODD=`expr $NUM % 4` if [ $ODD -ne 0 ]; then [ $LOGFILE ] && echo "${ODD} odd pages, adjusting..." >> $LOGFILE NUM=`expr $NUM + 4 - $NUM % 4` [ $LOGFILE ] && echo "Processing ${NUM} pages from ${FILE}..." >> $LOGFILE fi # Just see where psbook and mpage are... [ $LOGFILE ] && which psbook >> $LOGFILE [ $LOGFILE ] && which mpage >> $LOGFILE # Now, push $FILE through psbook and mpage and on to the printer [ $LOGFILE ] && psbook -s${NUM} $FILE | mpage -2 -bA4 -m60t10rlb -t -T > book.ps #psbook -s${NUM} $FILE | mpage -2 -bA4 -m60t10rlb -t -T -P${PRINTER} [ $LOGFILE ] || psbook -s${NUM} $FILE | mpage -2 -bA4 -m60t10rlb -t -T | ${PRINTER_COMMAND} # If the file came down a pipe, delete the temporary file [ $LOGFILE ] && [ "X${PIPE}" == "X1" ] && echo "Removing $FILE" >> $LOGFILE if [ ! $LOGFILE ]; then [ $PIPE ] && [ $PIPE -eq 1 ] && rm -f $FILE fi