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)
33 function cleanup-before-exit () {
37 trap cleanup-before-exit EXIT
41 if [ "${arg}" == "-h" ] || [ "${arg}" == "--help" ]; then
45 echo $(basename $0)" [<opt> ... <opt>] <file1> [[<opt> ... <opt>] <file2> ... ]"
47 echo "A dumb printing utility. Options:"
49 echo "-2pp two pages per page"
50 echo "-4pp four pages per page"
51 echo "-8pp eight pages per page"
52 echo "-gv displays the result with gv instead of printing"
53 echo "-stdout send the result to the standard output"
54 echo "-P<printer> uses <printer> instead of $PRINTER"
56 echo "Contact <francois.fleuret@epfl.ch>"
57 echo "Version \$Id: print.sh,v 1.19 2006-11-10 15:53:23 fleuret Exp $"
61 elif [[ ${arg} == "-"* ]]; then
63 # else, if it starts with '-' it is an option
69 # else, it is a filename to print
71 if [ -e "${arg}" ]; then
73 TYPE=$(file -L "${arg}")
80 convert "${arg}" ps:${tmp}
84 dvips -o ${tmp} "${arg}"
88 fig2dev -L ps "${arg}" > ${tmp}
96 pdf2ps "${arg}" ${tmp}
100 # a2ps -B -R --columns=1 -f 8 -o ${tmp} "${arg}"
101 # if isutf8 -q ${tmp}; then
102 # echo "Can not print uf8 text."
105 a2ps --media=A4 --user-option=lp -o ${tmp} "${arg}"
111 zcat "${arg}" > ${tmp}
117 echo "Unable to handle type \"$TYPE\""; noprint=1
123 if [ ! "$noprint" ]; then
125 # We apply all the filters seen up to now
130 tmp2=$(mktemp /tmp/filter.ps.XXXXXX)
131 psnup -d0 -m5 -2 < ${tmp} > ${tmp2}
135 tmp2=$(mktemp /tmp/filter.ps.XXXXXX)
136 psnup -d0 -m5 -4 < ${tmp} > ${tmp2}
140 tmp2=$(mktemp /tmp/filter.ps.XXXXXX)
141 psnup -d0 -m5 -8 < ${tmp} > ${tmp2}
154 PRINTER=$(echo $f | sed -e s/^-P//)
155 if [[ -z "$PRINTER" ]]; then
156 echo "Error in the printer name. Use -P<printer> with no space."
160 echo "Using printer \"$PRINTER\""
164 echo "Unknown option $f"
169 if [[ "$printing_cmd" == "lpr" ]]; then
170 echo "Printing on printer '$PRINTER'"
174 ${printing_cmd} ${tmp}
180 echo "Can not find file ${arg}"
188 if [[ ${show_queue} ]]; then