summarylogtreecommitdiffstats
path: root/gsfilter
blob: 4380cbacae010de8b6e4f82e0e501e3a2f269eb9 (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
45
46
47
48
49
50
51
52
53
54
55
#!/bin/sh
#
# gsfilter.simple -- HP deskjet or similar sample filter
#
# Requires pdftops from the xpdf package, the ghostscript package, and
# the enscript package.
#
# define temporary files
infile=/tmp/infile.$$
tempfile=/tmp/tempfile.$$
outfile=/tmp/outfile.$$

# choose your paper size
GSPAPER=letter
#GSPAPER=a4
PAPER=Letter
#PAPER=A4

# chose your printer device (run gs -h to see what is available)
DEVICE=cdjcolor

# 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`
ascii=`echo $fileinfo | grep ASCII`
pdf=`echo $fileinfo | grep PDF`
ps=`echo $fileinfo | grep PostScript`

# take various actions depending on the type of file -- send
# results to a temporary postscript file
if test "$ascii" != ''
then
    enscript -M $PAPER -o - $infile > $tempfile
elif test "$pdf" != ''
then
    pdftops -paper match $infile - > $tempfile
elif test "$ps" != ''
then
    cat $infile > $tempfile
else
    echo "Cannot print file of type  $fileinfo" | \
	enscript -M $PAPER -o - > $tempfile
fi

# run the postscript through gs to produce device output in a file
echo quit | gs -sOutputFile=$outfile -q -sPAPERSIZE=$GSPAPER -dSAFER \
    -dNOPAUSE -sDEVICE=$DEVICE $tempfile > /dev/null 2> /dev/null

# send output file to standard out
cat $outfile

# clean up
rm $infile $tempfile $outfile