3 #########################################################################
4 # This program is free software: you can redistribute it and/or modify #
5 # it under the terms of the version 3 of the GNU General Public License #
6 # as published by the Free Software Foundation. #
8 # This program is distributed in the hope that it will be useful, but #
9 # WITHOUT ANY WARRANTY; without even the implied warranty of #
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
11 # General Public License for more details. #
13 # You should have received a copy of the GNU General Public License #
14 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
16 # Written by and Copyright (C) Francois Fleuret #
17 # Contact <francois@fleuret.org> for comments & bug reports #
18 #########################################################################
22 # $Id: print.sh,v 1.19 2006-11-10 15:53:23 fleuret Exp $
25 echo "Need filenames to print!"
29 tmp=$(mktemp /tmp/print.ps.XXXXXX)
35 if [ "${arg}" == "-h" ] || [ "${arg}" == "--help" ]; then
39 echo $(basename $0)" [<opt> ... <opt>] <file1> [[<opt> ... <opt>] <file2> ... ]"
41 echo "A dumb printing utility. Options:"
43 echo "-2pp two pages per page"
44 echo "-4pp four pages per page"
45 echo "-8pp eight pages per page"
46 echo "-gv displays the result with gv instead of printing"
47 echo "-stdout send the result to the standard output"
48 echo "-P<printer> uses <printer> instead of $PRINTER"
50 echo "Contact <francois.fleuret@epfl.ch>"
51 echo "Version \$Id: print.sh,v 1.19 2006-11-10 15:53:23 fleuret Exp $"
56 elif [[ ${arg} == "-"* ]]; then
58 # else, if it starts with '-' it is an option
64 # else, it is a filename to print
66 if [ -e ${arg} ]; then
68 TYPE=$(file -L ${arg})
75 convert ${arg} ps:${tmp}
79 dvips -o ${tmp} ${arg}
83 fig2dev -L ps ${arg} > ${tmp}
95 # a2ps -B -R --columns=1 -f 8 -o ${tmp} ${arg}
96 a2ps --media=A4 --user-option=lp -o ${tmp} ${arg}
107 echo "Unable to handle type \"$TYPE\""; noprint=1
113 if [ ! "$noprint" ]; then
115 # We apply all the filters seen up to now
120 tmp2=$(mktemp /tmp/filter.ps.XXXXXX)
121 psnup -d0 -m5 -2 < ${tmp} > ${tmp2}
125 tmp2=$(mktemp /tmp/filter.ps.XXXXXX)
126 psnup -d0 -m5 -4 < ${tmp} > ${tmp2}
130 tmp2=$(mktemp /tmp/filter.ps.XXXXXX)
131 psnup -d0 -m5 -8 < ${tmp} > ${tmp2}
144 PRINTER=$(echo $f | sed -e s/^-P//)
145 if [[ -z "$PRINTER" ]]; then
146 echo "Error in the printer name. Use -P<printer> with no space."
150 echo "Using printer \"$PRINTER\""
154 echo "Unknown option $f"
160 if [[ "$printing_cmd" == "lpr" ]]; then
161 echo "Printing on printer '$PRINTER'"
165 ${printing_cmd} ${tmp}
171 echo "Can not find file ${arg}"
181 if [[ ${show_queue} ]]; then