Automatic paper selection using PostScript

懵懂的女人 提交于 2019-12-08 08:12:24

问题


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

  • How do I get the information of the bounding box of the page? Is there a standard or more documentation I could look into?
  • Would setting the PageSize like done in my sample code would be enough for the printer to select the right tray?
  • Is there a way to find out from the PPD file of the printer which PS commands are necessary to switch paper trays? In addition this printer has two trays for each size so it would be great if the printer would pick the full tray if one is out of paper.

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?


回答1:


If its possible, this is something the manufacturer usually incorporates. It requires that the printer know 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: 1) The /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 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 its legal (and for printers bleeds required) to have the PostScript output cover a larger area than the requested/intended medium.

2) Selecting a specific tray is usually device-dependent, you need to know how your device does this. I would like to think that manufacturers honour the MediaPosition key in the page device dictionary, but experience says this is unlikely. YMMV

3) The PPD may (or may not) include tray switching code, you'll have to look at the PPD and figure it out. 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.



来源:https://stackoverflow.com/questions/8072070/automatic-paper-selection-using-postscript

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!