[cups] Acquire paper and tray info

Johannes Meixner jsmeix at suse.de
Tue Jan 13 03:41:58 PST 2015


Hello,

On Jan 12 16:41 Paul Mitchell wrote (excerpt):
> /usr/share/cups/mime/mime.convs:
>
> application/postscript application/postscript-prefiltered 10 PsPrefilter 
> application/postscript-prefiltered application/vnd.cups-postscript 66 pstops
> #application/postscript application/vnd.cups-postscript 66 pstops
>
> /usr/share/cups/mime/mime.types, added below the applitcation-postscript 
> definition:
>
> application/postscript-prefiltered
> (without any arguments).
...
> D [12/Jan/2015:16:27:25 -0500] Print-Job
> client-error-document-format-not-supported:
> Unsupported format 'application/postscript'!
...
> It seems that the system has forgotten what to do with
> "application/postscript" event though we're telling it
> what to do in the mime.convs!

I didn't investigate why "application/postscript" does no longer work
because when you use a "System V style interface script" you do not need
to change the usual CUPS filtering rules (via its mime.* files).

https://en.opensuse.org/SDB:Using_Your_Own_Filters_to_Print_with_CUPS
mainly talks about how to change the usual CUPS filtering
by special filtering scripts.
The usage of "System V style interface script" is currently not
properly separated described there but basically mixed up with
the description of how to change the usual CUPS filtering.

When you use a "System V style interface script" that one is
the one and only filter that is run for any input data so that
the usual CUPS filtering rules that depend on the input data type
do not matter for a "System V style interface script".


What I did on my system (openSUSE 13.2 with CUPS 1.7.5):

For debugging I made a custom backend to get the final output
that is normally sent to the printer device into a file, see
https://en.opensuse.org/SDB:Using_Your_Own_Backends_to_Print_with_CUPS

On my system:
--------------------------------------------------------------------------
root at host# ls -l /usr/lib/cups/backend/myToFile
-rwxr-xr-x 1 root root 556 Jan 13 12:00 /usr/lib/cups/backend/myToFile

root at host# cat /usr/lib/cups/backend/myToFile
#! /bin/bash
# Have debug info in /var/log/cups/error_log:
set -x
# Output "device discovery" information on stdout:
if test "$#" = "0"
then echo 'direct myToFile:/tmp/myToFile.out "Unknown" "file output"'
      exit 0
fi
# Have the input at fd0 (stdin) in any case:
if test -n "$6"
then exec <"$6"
fi
echo 'INFO: sending data to /tmp/myToFile.out' 1>&2
# Forward the data from stdin to the file:
if cat - >/tmp/myToFile.out
then echo 'INFO:' 1>&2
      exit 0
else echo 'ERROR: failed to send data to /tmp/myToFile.out' 1>&2
      exit 1
fi
--------------------------------------------------------------------------

I made a "System V style interface script"
and a hello.ps PostScript file:

On my system:
--------------------------------------------------------------------------
root at host# cat /root/mySysVinterface.sh
#! /bin/bash
# see "man 7 filter"
# debug info in /var/log/cups/error_log
set -x
# have the input at fd0 (stdin) in any case
[ -n "$6" ] && exec <"$6"
# PJL init: Send "Universal Exit Language" command
echo -en '\033%-12345X'
# PJL stuff
echo -en '@PJL SET USERMEDIANAME="DV02"\n'
# PJL switch to PostScript
echo -en '@PJL ENTER LANGUAGE = POSTSCRIPT\n'
# Send the PostScript
cat -
# PostScript end of transmission and PJL end of job
echo -en '\004\033%-12345X\n'

root at host# cat /root/hello.ps
%!
/Helvetica findfont 20 scalefont setfont
100 200 moveto
(Hello) show
showpage
--------------------------------------------------------------------------

To let CUPS recognize my new custom backend I restarted the cupsd, see
https://en.opensuse.org/SDB:Using_Your_Own_Backends_to_Print_with_CUPS

On my system:
--------------------------------------------------------------------------
root at host# rccups restart

root at host# lpinfo -v | grep myToFile
direct myToFile:/tmp/myToFile.out
--------------------------------------------------------------------------

I set up a new queue for testing that uses my custom backend
and my "System V style interface script":

On my system:
--------------------------------------------------------------------------
root at host# lpadmin -p testy -v myToFile:/tmp/myToFile.out \
  -i /root/mySysVinterface.sh -E
--------------------------------------------------------------------------

I sent my hello.ps PostScript file to the new "testy" queue:

On my system:
--------------------------------------------------------------------------
root at host# lp -d testy /root/hello.ps
request id is testy-10 (1 file(s))

root at host# od -a /tmp/myToFile.out
0000000 esc   %   -   1   2   3   4   5   X   @   P   J   L  sp   S   E
0000020   T  sp   U   S   E   R   M   E   D   I   A   N   A   M   E   =
0000040   "   D   V   0   2   "  nl   @   P   J   L  sp   E   N   T   E
0000060   R  sp   L   A   N   G   U   A   G   E  sp   =  sp   P   O   S
0000100   T   S   C   R   I   P   T  nl   %   !  nl   /   H   e   l   v
0000120   e   t   i   c   a  sp   f   i   n   d   f   o   n   t  sp   2
0000140   0  sp   s   c   a   l   e   f   o   n   t  sp   s   e   t   f
0000160   o   n   t  nl   1   0   0  sp   2   0   0  sp   m   o   v   e
0000200   t   o  nl   (   H   e   l   l   o   )  sp   s   h   o   w  nl
0000220   s   h   o   w   p   a   g   e  nl  nl eot esc   %   -   1   2
0000240   3   4   5   X  nl
0000245
--------------------------------------------------------------------------

Excerpt from /var/log/cups/error_log for that print job on my system
(for debug logging you need "LogLevel debug" in /etc/cups/cupsd.conf
  plus a restart of the cupsd so that it runs with debug logging):
--------------------------------------------------------------------------
[Job 10] File of type application/postscript queued by "root".
...
[Job 10] 1 filters for job:
[Job 10] /etc/cups/interfaces/testy (application/postscript
  to printer/testy, cost 0)
...
[Job 10] Started filter /etc/cups/interfaces/testy (PID 2731)
[Job 10] Started backend /usr/lib/cups/backend/myToFile (PID 2732)
...
[Job 10] + test 5 = 0
[Job 10] + '[' -n /var/spool/cups/d00010-001 ']'
[Job 10] + exec
[Job 10] + echo -en '\033%-12345X'
[Job 10] + test -n ''
[Job 10] + echo -en '@PJL SET USERMEDIANAME="DV02"\n'
[Job 10] + echo 'INFO: sending data to /tmp/myToFile.out'
...
[Job 10] + echo -en '@PJL ENTER LANGUAGE = POSTSCRIPT\n'
[Job 10] + cat -
[Job 10] + cat -
[Job 10] + echo -en '\004\033%-12345X\n'
[Job 10] PID 2731 (/etc/cups/interfaces/testy) exited with no errors.
[Job 10] + echo INFO:
...
[Job 10] + exit 0
...
[Job 10] PID 2732 (/usr/lib/cups/backend/myToFile) exited with no errors.
...
[Job 10] Job completed.
--------------------------------------------------------------------------


Kind Regards
Johannes Meixner
-- 
SUSE LINUX GmbH - GF: Felix Imendoerffer, Jane Smithard, Jennifer Guild,
Dilip Upmanyu, Graham Norton - HRB 21284 (AG Nuernberg)




More information about the cups mailing list