take pstoricohddst-gdi from ustinov, fix dash
in fedora32 the original was not working any longer. Use version from ustinov and change %03d-page.pbm to %03d.page.pbm, because formatstring with dash was not working any longer. don't know why.
This commit is contained in:
parent
110a562096
commit
a4fcf2873d
2 changed files with 72 additions and 246 deletions
|
@ -1,189 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Debug mode: change to 'yes' to enable
|
|
||||||
DEBUG=${DEBUG-no}
|
|
||||||
|
|
||||||
function log() {
|
|
||||||
[ "${DEBUG}" = "yes" ] && echo $* | logger -t "$0[$$]"
|
|
||||||
}
|
|
||||||
|
|
||||||
function logpipe() {
|
|
||||||
[ "${DEBUG}" = "yes" ] && echo $* | logger -t "$0[$$]"
|
|
||||||
}
|
|
||||||
|
|
||||||
function trapINT() {
|
|
||||||
log "trapINT()"
|
|
||||||
[ "x$trp" = "x" ] && trp="yes" || return
|
|
||||||
sleep 30 && { [ ! "${DEBUG}" = "yes" ] && rm -rf $uid; log "Cleanup complete"; } &
|
|
||||||
exit
|
|
||||||
}
|
|
||||||
|
|
||||||
function stop() {
|
|
||||||
log "Stop stop page";
|
|
||||||
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 $*"
|
|
||||||
|
|
||||||
trap "stop; trapINT" SIGINT SIGTERM SIGQUIT
|
|
||||||
#trap 'echo No' SIGINT SIGTERM SIGQUIT EXIT;
|
|
||||||
# Username
|
|
||||||
user="$2"
|
|
||||||
|
|
||||||
# Page title (not used at this time, "Document" instead)
|
|
||||||
ptitle="$3"
|
|
||||||
my="$0"
|
|
||||||
options="$5"
|
|
||||||
|
|
||||||
pagesize="A4"
|
|
||||||
resolution="600"
|
|
||||||
mediasource="TRAY1"
|
|
||||||
for opt in $options; do
|
|
||||||
case "$opt" in
|
|
||||||
PageSize=*)
|
|
||||||
pagesize="$(echo "${opt#PageSize=}" | tr a-z A-Z)"
|
|
||||||
;;
|
|
||||||
Resolution=*)
|
|
||||||
resolution=${opt#Resolution=}
|
|
||||||
resolution=${resolution%dpi}
|
|
||||||
;;
|
|
||||||
InputSlot=*)
|
|
||||||
mediasource=${opt#InputSlot=}
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
# MS-style EOL
|
|
||||||
e=$(echo -en "\r")
|
|
||||||
|
|
||||||
# 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
|
|
||||||
[ "${DEBUG}" = "yes" ] && exec >$uid/output.stream #> >(tee $uid/output.stream)
|
|
||||||
|
|
||||||
[ -x "$(which inotifywait)" ] && {
|
|
||||||
log "Asynchronous variant"
|
|
||||||
|
|
||||||
(
|
|
||||||
stage="empty"
|
|
||||||
inotifywait -q -m -r -e close_write --format '%f' $uid | grep --line-buffered 'page.pbm$' | while read page; do
|
|
||||||
log "Page submitted"
|
|
||||||
[ "$stage" = "empty" ] && {
|
|
||||||
log "1st stage. Flushing PJL header"
|
|
||||||
output_header
|
|
||||||
stage="printing"
|
|
||||||
}
|
|
||||||
[ "$page" = "999999999-page.pbm" ] && {
|
|
||||||
log "Last stage. Flushing PJL footer"
|
|
||||||
output_footer
|
|
||||||
pid=`ps ax | grep $uid | grep -v grep | awk ' { print $1 } '`
|
|
||||||
[ ! "x$pid" = "x" ] && kill $pid
|
|
||||||
break
|
|
||||||
}
|
|
||||||
[ "$stage" = "printing" ] && {
|
|
||||||
page=$uid/$page
|
|
||||||
output_page
|
|
||||||
}
|
|
||||||
done
|
|
||||||
) &
|
|
||||||
|
|
||||||
# Converting from PostScript to PostScript-monochrome, then to PBM image format (per page)
|
|
||||||
#gs -sDEVICE=ps2write -sOutputFile=- -r$resolution -dQUIET -dBATCH -dNOPAUSE - |
|
|
||||||
gs -sDEVICE=pbmraw -sOutputFile=${uid}/%03d-page.pbm -r$resolution -dQUIET -dBATCH -dNOPAUSE -
|
|
||||||
|
|
||||||
stop
|
|
||||||
wait
|
|
||||||
|
|
||||||
trapINT
|
|
||||||
} || {
|
|
||||||
log "Synchronous variant"
|
|
||||||
|
|
||||||
# Converting from PostScript to PostScript-monochrome, then to PBM image format (per page)
|
|
||||||
log "Converting document to pages"
|
|
||||||
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"
|
|
||||||
|
|
||||||
output_header
|
|
||||||
|
|
||||||
for page in ${uid}/*-page.pbm; do
|
|
||||||
output_page
|
|
||||||
done
|
|
||||||
|
|
||||||
# Flushing PJL footer
|
|
||||||
output_footer
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
# only remove the output dir if not debugging
|
|
||||||
[ ! "${DEBUG}" = "yes" ] && rm -rf $uid;
|
|
||||||
|
|
||||||
exit 0
|
|
|
@ -1,7 +1,19 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
#Next four lines must be uncommented in MacOS
|
||||||
|
#GS=/opt/local/bin/gs
|
||||||
|
#PBMTOJBG=/opt/local/bin/pbmtojbg
|
||||||
|
#IDENTIFY=/opt/local/bin/identify
|
||||||
|
#uid="/var/spool/cups/tmp/pstoricohddst-gdi-`uuidgen`"
|
||||||
|
|
||||||
|
# Next four lines must be uncommented in Linux
|
||||||
|
GS=gs
|
||||||
|
PBMTOJBG=pbmtojbg
|
||||||
|
IDENTIFY=identify
|
||||||
|
uid="/tmp/pstoricohddst-gdi-`uuidgen`"
|
||||||
|
|
||||||
# Debug mode: change to 'yes' to enable
|
# Debug mode: change to 'yes' to enable
|
||||||
DEBUG=${DEBUG-no}
|
DEBUG=${DEBUG+no}
|
||||||
|
|
||||||
function log() {
|
function log() {
|
||||||
[ "${DEBUG}" = "yes" ] && echo $* | logger -t "$0[$$]"
|
[ "${DEBUG}" = "yes" ] && echo $* | logger -t "$0[$$]"
|
||||||
|
@ -20,32 +32,23 @@ function trapINT() {
|
||||||
|
|
||||||
function stop() {
|
function stop() {
|
||||||
log "Stop stop page";
|
log "Stop stop page";
|
||||||
echo "stop" > $uid/999999999-page.pbm
|
echo "stop" > $uid/999999999.page.pbm
|
||||||
}
|
}
|
||||||
|
|
||||||
function output_page() {
|
function pageOutput() {
|
||||||
|
|
||||||
# Converting page to JBIG format (parameters are very special for this printer!)
|
# Converting page to JBIG format (parameters are very special for this printer!)
|
||||||
pbmtojbg -p 72 -o 3 -m 0 -q < $page > $uid/raster.jbig
|
$PBMTOJBG -p 72 -o 3 -m 0 -q < $uid/$page > $uid/raster.jbig
|
||||||
|
|
||||||
# Taking image size
|
# Taking image size
|
||||||
jsize=`wc -c < $uid/raster.jbig`
|
jsize=`wc -c < $uid/raster.jbig | awk ' { printf($1); }' `
|
||||||
|
|
||||||
# Taking image dimensions
|
# Taking image dimensions
|
||||||
x=($(identify -format "%w %h %[fx:mean] " $page))
|
#read fn ft xs ys garb < <($IDENTIFY $uid/$page | tr "x" " ") #Not work under MacOS
|
||||||
##
|
ident=`$IDENTIFY $uid/$page | tr "x" " "`
|
||||||
# The %[fx:mean] gives the average colour in the image which for
|
xs=`echo $ident | awk ' { print $3 } '`
|
||||||
# monochrome is the number of white pixels divided by the size
|
ys=`echo $ident | awk ' { print $4 } '`
|
||||||
#
|
log "Identified as ${xs}x${ys}"
|
||||||
# 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
|
# Flushing page header
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
|
@ -54,23 +57,26 @@ function output_page() {
|
||||||
@PJL SET MEDIASOURCE=$mediasource$e
|
@PJL SET MEDIASOURCE=$mediasource$e
|
||||||
@PJL SET MEDIATYPE=PLAINRECYCLE$e
|
@PJL SET MEDIATYPE=PLAINRECYCLE$e
|
||||||
@PJL SET PAPER=$pagesize$e
|
@PJL SET PAPER=$pagesize$e
|
||||||
@PJL SET PAPERWIDTH=${x[0]}$e
|
@PJL SET PAPERWIDTH=$xs$e
|
||||||
@PJL SET PAPERLENGTH=${x[1]}$e
|
@PJL SET PAPERLENGTH=$ys$e
|
||||||
@PJL SET RESOLUTION=${resolution%x600}$e
|
@PJL SET RESOLUTION=${resolution%x600}$e
|
||||||
@PJL SET IMAGELEN=$jsize$e
|
@PJL SET IMAGELEN=$jsize$e
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
# Flushing image
|
||||||
cat $uid/raster.jbig
|
cat $uid/raster.jbig
|
||||||
|
|
||||||
# Flushing page footer
|
# Flushing page footer
|
||||||
# TODO: pixelcount for toner estimate
|
# TODO: pixelcount for toner estimate
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
@PJL SET DOTCOUNT=$dots$e
|
@PJL SET DOTCOUNT=1132782$e
|
||||||
@PJL SET PAGESTATUS=END$e
|
@PJL SET PAGESTATUS=END$e
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
#end of pageOutput
|
||||||
}
|
}
|
||||||
|
|
||||||
function output_header() {
|
function pjlHeader() {
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
%-12345X@PJL$e
|
%-12345X@PJL$e
|
||||||
@PJL SET TIMESTAMP=$ddate$e
|
@PJL SET TIMESTAMP=$ddate$e
|
||||||
|
@ -82,10 +88,10 @@ function output_header() {
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
function output_footer() {
|
function pjlFooter() {
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
@PJL EOJ$e
|
@PJL EOJ$e
|
||||||
%-12345X
|
%-12345X$e
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,9 +134,9 @@ ddate="`LC_ALL=en_US.UTF-8 date '+%Y/%m/%d %H:%M:%S'`"
|
||||||
# Temporary directory
|
# Temporary directory
|
||||||
uid="/tmp/pstoricohddst-gdi-`uuidgen`"
|
uid="/tmp/pstoricohddst-gdi-`uuidgen`"
|
||||||
mkdir -p $uid
|
mkdir -p $uid
|
||||||
[ "${DEBUG}" = "yes" ] && exec >$uid/output.stream #> >(tee $uid/output.stream)
|
[ "${DEBUG}" = "yes" ] && exec >$uid/output.stream #> >(tee $uid/output.stream) #does not work under MacOS
|
||||||
|
|
||||||
[ -x "$(which inotifywait)" ] && {
|
if [ -x "$(which inotifywait)" ]; then {
|
||||||
log "Asynchronous variant"
|
log "Asynchronous variant"
|
||||||
|
|
||||||
(
|
(
|
||||||
|
@ -139,51 +145,60 @@ 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"
|
||||||
output_header
|
pjlHeader;
|
||||||
|
|
||||||
stage="printing"
|
stage="printing"
|
||||||
}
|
}
|
||||||
[ "$page" = "999999999-page.pbm" ] && {
|
[ "$page" = "999999999.page.pbm" ] && {
|
||||||
log "Last stage. Flushing PJL footer"
|
log "Last stage. Flushing PJL footer"
|
||||||
output_footer
|
pjlFooter;
|
||||||
|
|
||||||
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" ] && {
|
||||||
page=$uid/$page
|
pageOutput;
|
||||||
output_page
|
|
||||||
}
|
}
|
||||||
done
|
done
|
||||||
) &
|
) &
|
||||||
|
|
||||||
# Converting from PostScript to PostScript-monochrome, then to PBM image format (per page)
|
# Converting from PostScript to PostScript-monochrome, then to PBM image format (per page)
|
||||||
#gs -sDEVICE=ps2write -sOutputFile=- -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 -
|
$GS -sDEVICE=pbmraw -sOutputFile=${uid}/%03d.page.pbm -r$resolution -dQUIET -dBATCH -dNOPAUSE -
|
||||||
|
|
||||||
stop
|
stop
|
||||||
wait
|
wait
|
||||||
|
|
||||||
trapINT
|
trapINT
|
||||||
} || {
|
}
|
||||||
|
else {
|
||||||
log "Synchronous variant"
|
log "Synchronous variant"
|
||||||
|
mkdir ${uid}/gs-temp
|
||||||
|
export TEMP=${uid}/gs-temp
|
||||||
|
|
||||||
# Converting from PostScript to PostScript-monochrome, then to PBM image format (per page)
|
# Converting from PostScript to PostScript-monochrome, then to PBM image format (per page)
|
||||||
log "Converting document to pages"
|
log "Converting document to pages"
|
||||||
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"
|
||||||
|
|
||||||
output_header
|
pjlHeader;
|
||||||
|
|
||||||
|
ls -1 $uid | grep "page.pbm" | while read page; do
|
||||||
|
#for page in ${uid}/*.page.pbm; do #looks untested - does not work
|
||||||
|
log "Page $page"
|
||||||
|
|
||||||
|
pageOutput;
|
||||||
|
|
||||||
for page in ${uid}/*-page.pbm; do
|
|
||||||
output_page
|
|
||||||
done
|
done
|
||||||
|
|
||||||
# Flushing PJL footer
|
# Flushing PJL footer
|
||||||
output_footer
|
pjlFooter;
|
||||||
|
|
||||||
|
if [ ! "${DEBUG}" = "yes" ]; then
|
||||||
|
rm -rf $uid
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
fi
|
||||||
# only remove the output dir if not debugging
|
|
||||||
[ ! "${DEBUG}" = "yes" ] && rm -rf $uid;
|
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
Loading…
Reference in a new issue