aboutsummarylogtreecommitdiffstats
path: root/foofilter
blob: 8fde8fe2a97aeacf1938b5d4b3bb6cb3e196299a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/sh
#
# foofilter.sh -- Foomatic-rip-lprng is used as the print filter
#
# Requires
#    poppler (xpdf): pdftops
#    foomatic-filters-lprng
#    enscript

set -u

# define temporary files
infile="/tmp/infile.$$"
tempfile="/tmp/tempfile.$$"

# replace example.ppd with the appropriate ppd file for your printer
your_ppd="${example}.ppd"

# choose your paper size
PAPER='Letter'
#PAPER='A4'

# send the standard input to a temporary file
cat > "${infile}"

# figure out what type of file we are trying to print
fileinfo="$(file -b "${infile}")"

# take various actions depending on the type of file -- send
# results to a temporary postscript file
case "${fileinfo}" in
*ASCII*)      enscript -M "${PAPER}" -o - "${infile}" > "${tempfile}" ;;
*PDF*)        pdftops "${infile}" - > "${tempfile}" ;;
*PostScript*) cat "${infile}" > "${tempfile}" ;;
*)
  echo "Cannot print file of type ${fileinfo}" | \
  enscript -M "${PAPER}" -o - > "${tempfile}"
  ;;
esac

# foomatic-rip sends stuff to the standard output
/usr/bin/foomatic-rip-lprng --lprng "/etc/lprng/lpd/${your_ppd}" < "${tempfile}"

rm -f "${infile}" "${tempfile}"