使用javax.print打印时,选择箱子/托盘

使用javax.print打印时,选择箱子/托盘,java,printing,Java,Printing,我想在使用Java打印时指定输入箱。我找到了MediaTray类,它应该对应于输入箱: The following standard values are defined for input-trays (from ISO DPA and the Printer MIB): 'top': The top input tray in the printer. 'middle': The middle input tray in the printer. 'bottom': The bottom

我想在使用Java打印时指定输入箱。我找到了MediaTray类,它应该对应于输入箱:

The following standard values are defined for input-trays (from ISO
DPA and the Printer MIB):

'top': The top input tray in the printer.
'middle': The middle input tray in the printer.
'bottom': The bottom input tray in the printer.
'envelope': The envelope input tray in the printer.
'manual': The manual feed input tray in the printer.
'large-capacity': The large capacity input tray in the printer.
'main': The main input tray
'side': The side input tray
资料来源:

问题是,我从指定输入箱的应用程序中获得一个数字。我可以简单地映射枚举int值吗?或者用数字获取枚举值的常用方法是什么?官方是否支持对托盘进行编号

我在RFC中找不到与输出箱对应的属性。有没有办法做到这一点

最重要的问题是:打印机界面是否可靠?我找到的大多数关于托盘的帖子最终都放弃了,因为他们无法让它工作


任何经验都将不胜感激。

这些属性在中定义。另请参见。

如果您想使用实际托盘编号而不是TOP等常规常量,则必须进行一些额外的编码。 没有任何枚举列出给定打印机的所有纸盘编号,因为编码时不知道将有多少纸盘。 您需要在打印机服务中查询attributetype Media.class支持的所有属性值。这将为您提供不同类型的列表。 打印结果时,托盘应位于此列表中的某个位置。重要的是从这个列表中取出托盘,而不是自己构建它,因为打印框架中的一些内部代码与此相关

注: 打印api有一些与纸盘打印相关的错误,特别是在unix上。 要快速解决这些问题,请投票支持: 和/或

这是如何打印到纸盘1(如果存在):

PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
Media[] supportedMedia = (Media[]) prnJob.getPrintService().getSupportedAttributeValues(Media.class, null, null);
for (Media m : supportedMedia) {
    if (m.toString().equals("Tray 1")) {
        aset.add(m);
        break;
    }
}

最重要的问题是:打印机界面是否可靠?也许这个API是Sun/Oracle对环保主义的贡献“拯救树木!”;如问题中所述,我已经找到了MediaTray。您发布的文章包含许多有用的信息,例如,如何为MediaTray的字符串属性创建子类。但是,我在其中找不到明确的信息来回答我的一个问题。您提到应用程序通过数字指定输入箱。什么申请?该编号方案是否记录在任何地方?在不知道的情况下,您可以将该数字与特定MediaTray常量的EnumSyntaxgetValue进行比较。直接检查“MediaTray”常量可能更容易,例如顶部为0,中间为1等。我无法告诉您应用程序的名称。无论如何,我将尝试使用常量的值,看看它是否有效。由于这是唯一能进一步帮助我的答案,我将接受它作为一个答案。谢谢。@box:谢谢。如果您添加答案或更新问题,请在评论中Ping我。