使用PostScript自动选择纸张 [英] Automatic paper selection using PostScript

查看:285
本文介绍了使用PostScript自动选择纸张的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有多个装有A4和A3纸的纸盘的PostScript 3打印机有问题。在使用CUPS系统的Linux下,我现在通过指定media = a4选项或定义两个单独的打印机来手动设置正确的纸张尺寸:一个用于A4,一个用于A3。



但是这种情况远非最佳,因为您总是要记住选择正确的打印机。



由于PostScript是一种图灵完整的语言,在阅读了几篇文章之后红皮书蓝皮书我有一个问题:



有可能吗?修改打印机的PPD文件以生成自动选纸尺寸选项,如果激活该选项,则会自动设置正确的介质尺寸?也许取决于打印输出的边框大小?



也许是这样开始的:



PostScript代码

 %设置页面大小A4 
/ setA4Paper {<< / PageSize [595 842]>> setpagedevice} def
%设置页面大小A3
/ setA3Paper {< / PageSize [842 1190]> setpagedevice} def
%根据边界框
%(两个元素,宽度和高度的数组)决定要采用的纸张尺寸
%如果边界框比A4纸宽,请选择A3纸
boundingBox 0得到595 gt {setA3Paper} {setA4Paper} ifelse

详细问题




  • 如何获取页面边界框的信息?有没有我可以研究的标准文档或更多文档?

  • 像样例代码中那样设置PageSize是否足以让打印机选择正确的纸盒?

  • 是否可以从打印机的PPD文件中找出切换纸盒所需的PS命令?另外,此打印机有两种尺寸的纸盘,因此如果一个纸盘中的纸张用完了,那么打印机将选择完整的纸盘将非常好。



编辑



从KenS的答案看来,没有简单的方法可以直接从PostScript中获取边界框。有没有办法在将PS文件发送回CUPS队列之前或发送给打印机之前,通过自定义脚本路由它?

解决方案

如果可能的话,这是制造商通常采用的方法。它要求打印机知道哪个纸盘包含哪种介质。有些打印机确实具有此信息,有些则没有。对于某些打印机,它当然是固定的。



对于您的详细问题:
1)页面设备字典中的/ PageSize键具有当前请求的介质尺寸。 setpagedevice运算符用于请求媒体(以及其他任何东西)。如果您的PostScript文件不包含媒体选择运算符(例如setpagedevice等),则它可能包含给出BoundingBox的注释。大多数口译员将忽略这些内容(它们是注释),但有些可能会允许您处理它们。通常,这高度依赖于设备。



如果作业未定义页面边界框,则无法(在PostScript中)获取页面边界框,这是因为它是合法的(并且要求打印机有出血),以使PostScript输出覆盖的区域大于所请求/预定的介质。



2)选择特定的纸盘通常是一种设备依赖,您需要知道您的设备如何做到这一点。我想认为制造商尊重页面设备字典中的MediaPosition键,但是经验表明这不太可能。 YMMV



3)PPD 可能(或可能不包括)托盘切换代码,您必须查看PPD并弄清楚它出来。至于在现有托盘为空的情况下选择完整托盘,这确实超出了PostScript程序的范围,并取决于制造商的实现。
在语言3级设备中,页面设备字典中的TraySwitch键控制自动托盘切换,请参阅《 PostScript语言参考手册》(第3版)p403,因此,由于您拥有3级设备,因此可能会很幸运。 p>

由于您已经在使用CUPS,因此可以使用bbox设备通过Ghostscript运行原始的PostScript / PDF,这将为您提供标记的边框在页面上。只要您有理由确定自己(或您的用户)没有设置超出媒体范围的标记。然后,您可以使用这些信息来选择合适的打印机。



注意:我对CUPS知之甚少。


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?

解决方案

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.

这篇关于使用PostScript自动选择纸张的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆