73 lines
1.6 KiB
Bash
Executable file
73 lines
1.6 KiB
Bash
Executable file
#!/bin/bash
|
||
|
||
# Username
|
||
user="$2"
|
||
|
||
# Page title (not used at this time, "Document" instead)
|
||
ptitle="$3"
|
||
|
||
# Printing date
|
||
ddate="`LC_ALL=en_US.UTF-8 date '+%Y/%m/%d %H:%M:%S'`"
|
||
|
||
# Temporary directory
|
||
uid="/tmp/pstoricohddst-gdi-`uuidgen`"
|
||
mkdir -p $uid
|
||
|
||
# Converting from PostScript to PostScript-monochrome, then to PBM image format (per page)
|
||
gs -sDEVICE=psmono -sOutputFile=- -r600 -dQUIET -dBATCH -dNOPAUSE - | gs -sDEVICE=pbmraw -sOutputFile=${uid}/%d-page.pbm -r600 -dQUIET -dBATCH -dNOPAUSE -
|
||
|
||
# Flushing PJL header
|
||
cat <<EOF
|
||
%-12345X@PJL
|
||
@PJL SET TIMESTAMP=$ddate
|
||
@PJL SET FILENAME=Document
|
||
@PJL SET COMPRESS=JBIG
|
||
@PJL SET USERNAME=$user
|
||
@PJL SET COVER=OFF
|
||
@PJL SET HOLD=OFF
|
||
EOF
|
||
|
||
ls $uid/ | grep 'pbm$' | sort -n | while read page; do
|
||
|
||
# Converting page to JBIG format (parameters are very special for this printer!)
|
||
pbmtojbg -p 72 -o 3 -m 0 -q < $uid/$page > $uid/raster.jbig
|
||
|
||
# Taking image size
|
||
jsize=`wc -c < $uid/raster.jbig`
|
||
|
||
# Taking image dimensions
|
||
read fn ft xs ys garb < <(identify $uid/raster.jbig | tr "x" " ")
|
||
|
||
# Flushing page header
|
||
cat <<EOF
|
||
@PJL SET PAGESTATUS=START
|
||
@PJL SET COPIES=1
|
||
@PJL SET MEDIASOURCE=AUTO
|
||
@PJL SET MEDIATYPE=PLAINRECYCLE
|
||
@PJL SET PAPER=A4
|
||
@PJL SET PAPERWIDTH=$xs
|
||
@PJL SET PAPERLENGTH=$ys
|
||
@PJL SET RESOLUTION=600
|
||
@PJL SET IMAGELEN=$jsize
|
||
EOF
|
||
|
||
# Flushing image
|
||
cat $uid/raster.jbig
|
||
|
||
# Flushing page footer
|
||
# TODO: pixelcount for toner estimate
|
||
cat <<EOF
|
||
@PJL SET DOTCOUNT=1132782
|
||
@PJL SET PAGESTATUS=END
|
||
EOF
|
||
|
||
done
|
||
|
||
# Flushing PJL footer
|
||
cat <<EOF
|
||
@PJL EOJ
|
||
%-12345X
|
||
EOF
|
||
|
||
# Cleaning up
|
||
rm -rf $uid
|