dot-issue solved
This commit is contained in:
parent
105dd8ae9e
commit
1eabc36369
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Debug mode: change to 'yes' to enable
|
# Debug mode: change to 'yes' to enable
|
||||||
DEBUG=no
|
DEBUG=${DEBUG-no}
|
||||||
|
|
||||||
function log() {
|
function log() {
|
||||||
[ "${DEBUG}" = "yes" ] && echo $* | logger -t "$0[$$]"
|
[ "${DEBUG}" = "yes" ] && echo $* | logger -t "$0[$$]"
|
||||||
|
@ -23,6 +23,72 @@ function stop() {
|
||||||
echo "stop" > $uid/999999999-page.pbm
|
echo "stop" > $uid/999999999-page.pbm
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function output_page() {
|
||||||
|
# Converting page to JBIG format (parameters are very special for this printer!)
|
||||||
|
pbmtojbg -p 72 -o 3 -m 0 -q < $page > $uid/raster.jbig
|
||||||
|
|
||||||
|
# Taking image size
|
||||||
|
jsize=`wc -c < $uid/raster.jbig`
|
||||||
|
|
||||||
|
# Taking image dimensions
|
||||||
|
x=($(identify -format "%w %h %[fx:mean] " $page))
|
||||||
|
##
|
||||||
|
# The %[fx:mean] gives the average colour in the image which for
|
||||||
|
# monochrome is the number of white pixels divided by the size
|
||||||
|
#
|
||||||
|
# So the formula gives the number of black pixels. The final
|
||||||
|
# /1 causes bc to round to the nearest integer because scale=0
|
||||||
|
##
|
||||||
|
dots=$(echo "(${x[0]}*${x[1]}*(1-${x[2]}))/1"|bc)
|
||||||
|
##
|
||||||
|
# FIX: toner cartridge runs out way too fast with this dots
|
||||||
|
# calculation above and once it decides it's empty, you
|
||||||
|
# can't force it to print. So set dots to an artificially
|
||||||
|
# low number
|
||||||
|
dots=$(echo "$dots/10"|bc)
|
||||||
|
|
||||||
|
# Flushing page header
|
||||||
|
cat <<EOF
|
||||||
|
@PJL SET PAGESTATUS=START$e
|
||||||
|
@PJL SET COPIES=1$e
|
||||||
|
@PJL SET MEDIASOURCE=$mediasource$e
|
||||||
|
@PJL SET MEDIATYPE=PLAINRECYCLE$e
|
||||||
|
@PJL SET PAPER=$pagesize$e
|
||||||
|
@PJL SET PAPERWIDTH=${x[0]}$e
|
||||||
|
@PJL SET PAPERLENGTH=${x[1]}$e
|
||||||
|
@PJL SET RESOLUTION=${resolution%x600}$e
|
||||||
|
@PJL SET IMAGELEN=$jsize$e
|
||||||
|
EOF
|
||||||
|
|
||||||
|
cat $uid/raster.jbig
|
||||||
|
|
||||||
|
# Flushing page footer
|
||||||
|
# TODO: pixelcount for toner estimate
|
||||||
|
cat <<EOF
|
||||||
|
@PJL SET DOTCOUNT=$dots$e
|
||||||
|
@PJL SET PAGESTATUS=END$e
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
function output_header() {
|
||||||
|
cat <<EOF
|
||||||
|
%-12345X@PJL$e
|
||||||
|
@PJL SET TIMESTAMP=$ddate$e
|
||||||
|
@PJL SET FILENAME=Document$e
|
||||||
|
@PJL SET COMPRESS=JBIG$e
|
||||||
|
@PJL SET USERNAME=$user$e
|
||||||
|
@PJL SET COVER=OFF$e
|
||||||
|
@PJL SET HOLD=OFF$e
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
function output_footer() {
|
||||||
|
cat <<EOF
|
||||||
|
@PJL EOJ$e
|
||||||
|
%-12345X
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
log "Called with cmdline: $0 $*"
|
log "Called with cmdline: $0 $*"
|
||||||
|
|
||||||
trap "stop; trapINT" SIGINT SIGTERM SIGQUIT
|
trap "stop; trapINT" SIGINT SIGTERM SIGQUIT
|
||||||
|
@ -73,60 +139,19 @@ mkdir -p $uid
|
||||||
log "Page submitted"
|
log "Page submitted"
|
||||||
[ "$stage" = "empty" ] && {
|
[ "$stage" = "empty" ] && {
|
||||||
log "1st stage. Flushing PJL header"
|
log "1st stage. Flushing PJL header"
|
||||||
cat <<EOF
|
output_header
|
||||||
%-12345X@PJL$e
|
|
||||||
@PJL SET TIMESTAMP=$ddate$e
|
|
||||||
@PJL SET FILENAME=Document$e
|
|
||||||
@PJL SET COMPRESS=JBIG$e
|
|
||||||
@PJL SET USERNAME=$user$e
|
|
||||||
@PJL SET COVER=OFF$e
|
|
||||||
@PJL SET HOLD=OFF$e
|
|
||||||
EOF
|
|
||||||
|
|
||||||
stage="printing"
|
stage="printing"
|
||||||
}
|
}
|
||||||
[ "$page" = "999999999-page.pbm" ] && {
|
[ "$page" = "999999999-page.pbm" ] && {
|
||||||
log "Last stage. Flushing PJL footer"
|
log "Last stage. Flushing PJL footer"
|
||||||
cat <<EOF
|
output_footer
|
||||||
@PJL EOJ$e
|
|
||||||
%-12345X
|
|
||||||
EOF
|
|
||||||
pid=`ps ax | grep $uid | grep -v grep | awk ' { print $1 } '`
|
pid=`ps ax | grep $uid | grep -v grep | awk ' { print $1 } '`
|
||||||
[ ! "x$pid" = "x" ] && kill $pid
|
[ ! "x$pid" = "x" ] && kill $pid
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
[ "$stage" = "printing" ] && {
|
[ "$stage" = "printing" ] && {
|
||||||
# Converting page to JBIG format (parameters are very special for this printer!)
|
page=$uid/$page
|
||||||
pbmtojbg -p 72 -o 3 -m 0 -q < $uid/$page > $uid/raster.jbig
|
output_page
|
||||||
|
|
||||||
# Taking image size
|
|
||||||
jsize=`wc -c < $uid/raster.jbig`
|
|
||||||
|
|
||||||
# Taking image dimensions
|
|
||||||
read fn ft xs ys garb < <(identify $uid/$page | tr "x" " ")
|
|
||||||
|
|
||||||
# Flushing page header
|
|
||||||
cat <<EOF
|
|
||||||
@PJL SET PAGESTATUS=START$e
|
|
||||||
@PJL SET COPIES=1$e
|
|
||||||
@PJL SET MEDIASOURCE=$mediasource$e
|
|
||||||
@PJL SET MEDIATYPE=PLAINRECYCLE$e
|
|
||||||
@PJL SET PAPER=$pagesize$e
|
|
||||||
@PJL SET PAPERWIDTH=$xs$e
|
|
||||||
@PJL SET PAPERLENGTH=$ys$e
|
|
||||||
@PJL SET RESOLUTION=${resolution%x600}$e
|
|
||||||
@PJL SET IMAGELEN=$jsize$e
|
|
||||||
EOF
|
|
||||||
|
|
||||||
log "Flushing image $page"
|
|
||||||
cat $uid/raster.jbig
|
|
||||||
|
|
||||||
# Flushing page footer
|
|
||||||
# TODO: pixelcount for toner estimate
|
|
||||||
cat <<EOF
|
|
||||||
@PJL SET DOTCOUNT=1132782$e
|
|
||||||
@PJL SET PAGESTATUS=END$e
|
|
||||||
EOF
|
|
||||||
}
|
}
|
||||||
done
|
done
|
||||||
) &
|
) &
|
||||||
|
@ -147,61 +172,18 @@ EOF
|
||||||
gs -sDEVICE=ps2write -sOutputFile=- -r$resolution -dQUIET -dBATCH -dNOPAUSE - | gs -sDEVICE=pbmraw -sOutputFile=${uid}/%03d-page.pbm -r$resolution -dQUIET -dBATCH -dNOPAUSE -
|
gs -sDEVICE=ps2write -sOutputFile=- -r$resolution -dQUIET -dBATCH -dNOPAUSE - | gs -sDEVICE=pbmraw -sOutputFile=${uid}/%03d-page.pbm -r$resolution -dQUIET -dBATCH -dNOPAUSE -
|
||||||
log "Conversion complete"
|
log "Conversion complete"
|
||||||
|
|
||||||
cat <<EOF
|
output_header
|
||||||
%-12345X@PJL$e
|
|
||||||
@PJL SET TIMESTAMP=$ddate$e
|
|
||||||
@PJL SET FILENAME=Document$e
|
|
||||||
@PJL SET COMPRESS=JBIG$e
|
|
||||||
@PJL SET USERNAME=$user$e
|
|
||||||
@PJL SET COVER=OFF$e
|
|
||||||
@PJL SET HOLD=OFF$e
|
|
||||||
EOF
|
|
||||||
|
|
||||||
for page in ${uid}/*-page.pbm; do
|
for page in ${uid}/*-page.pbm; do
|
||||||
|
output_page
|
||||||
log "Page $page"
|
|
||||||
# Converting page to JBIG format (parameters are very special for this printer!)
|
|
||||||
pbmtojbg -p 72 -o 3 -m 0 -q < $page > $uid/raster.jbig
|
|
||||||
|
|
||||||
# Taking image size
|
|
||||||
jsize=`wc -c < $uid/raster.jbig`
|
|
||||||
|
|
||||||
# Taking image dimensions
|
|
||||||
read fn ft xs ys garb < <(identify $page | tr "x" " ")
|
|
||||||
log "Identified as ${xs}x${ys}"
|
|
||||||
|
|
||||||
# Flushing page header
|
|
||||||
cat <<EOF
|
|
||||||
@PJL SET PAGESTATUS=START$e
|
|
||||||
@PJL SET COPIES=1$e
|
|
||||||
@PJL SET MEDIASOURCE=$mediasource$e
|
|
||||||
@PJL SET MEDIATYPE=PLAINRECYCLE$e
|
|
||||||
@PJL SET PAPER=$pagesize$e
|
|
||||||
@PJL SET PAPERWIDTH=$xs$e
|
|
||||||
@PJL SET PAPERLENGTH=$ys$e
|
|
||||||
@PJL SET RESOLUTION=${resolution%x600}$e
|
|
||||||
@PJL SET IMAGELEN=$jsize$e
|
|
||||||
EOF
|
|
||||||
|
|
||||||
# Flushing image
|
|
||||||
cat $uid/raster.jbig
|
|
||||||
|
|
||||||
# Flushing page footer
|
|
||||||
# TODO: pixelcount for toner estimate
|
|
||||||
cat <<EOF
|
|
||||||
@PJL SET DOTCOUNT=1132782$e
|
|
||||||
@PJL SET PAGESTATUS=END$e
|
|
||||||
EOF
|
|
||||||
done
|
done
|
||||||
|
|
||||||
# Flushing PJL footer
|
# Flushing PJL footer
|
||||||
cat <<EOF
|
output_footer
|
||||||
@PJL EOJ$e
|
|
||||||
%-12345X
|
|
||||||
EOF
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#rm -rf $uid;
|
# only remove the output dir if not debugging
|
||||||
|
[ ! "${DEBUG}" = "yes" ] && rm -rf $uid;
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
Loading…
Reference in a new issue