I have a problem with a PostScript 3 printer with multiple trays which are loaded with A4 and A3 paper. Under Linux using the CUPS system I am now manually setting the right paper size by specifying a media=a4 option or defining two separate printers: one for A4 and one for A3.
However this situation is far from being optimal as you always have to remember to pick the right printer.
As PostScript is a turing-complete language and after reading a bit in the Red Book and the Blue Book I have a question:
Is it possible to modify the printer's PPD file to generate a 'pick paper size automatically' option, which if activated sets the right media size automatically? Maybe depending on the bounding box size of the print out?
Maybe something starting like this:
PostScript Code
% set pagesize A4
/setA4Paper {<</PageSize [595 842] >> setpagedevice} def
% set pagesize A3
/setA3Paper {<</PageSize [842 1190] >> setpagedevice} def
% decide which paper size to take based on the bounding box
% (array of two elements, width and height)
% if the bounding box is wider that A4 paper, pick A3 paper instead
boundingBox 0 get 595 gt {setA3Paper} {setA4Paper} ifelse
Detail questions
EDIT
From KenS' answer it seems that there is no easy way of getting the bounding box directly out of the PostScript. Is there a way to route a PS file through a custom script before sending it back into the CUPS queue or before it is sent to the printer?
If it's possible, this is something the manufacturer usually incorporates. It requires that the printer knows which tray contains which medium. Some printers do have this information, some don't. For some printers its fixed, of course.
For your detailed questions:
/PageSize
key in the page device dictionary has the currently requested media size. The setpagedevice
operator is used to request media (amongst any other things). if your PostScript file doesn't contain media selection operators (setpagedevice
, etc.) then it may (actually it should) contain comments which give the BoundingBox:
. Most interpreters will ignore these (they are comments) but some may allow you to process them. This is generally highly device-dependent.There is no way (in PostScript) to get the Bounding Box of the page if the job doesn't define it, this is because it's legal (and for printers bleeds required) to have the PostScript output cover a larger area than the requested/intended medium.
Selecting a specific tray is usually device-dependent, you need to know how your device does this. I would like to think that manufacturers honor the MediaPosition
key in the page device dictionary, but experience says this is unlikely. YMMV
The PPD may (or may not) include tray switching code, you'll have to look at the PPD and figure it out (look for InputSlot
). As for selecting a full tray if an existing one is empty, this truly is out of the domain of the PostScript program and up to the manufacturer's implementation.
In language level 3 devices the TraySwitch
key in the page device dictionary controls automatic tray switching, see the PostScript Language Reference Manual (3rd edition) p403 so since you have a level 3 device, you might be in luck.
Since you are already using CUPS you could run the original PostScript/PDF through Ghostscript using the bbox device which would give you the bounding box of the marks on the page. As long as you are reasonably sure you (or your users) aren't setting marks beyond the media boundaries. Then you could use that information to select the right 'printer' I think.
Caveat: I know very little about CUPS.