2011-10-01 46 views
4

我想在使用Java打印時指定輸入紙盒。我發現這應該對應於輸入箱櫃MediaTray類:使用javax.print打印時選擇紙盒/紙盒

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 

來源:http://tools.ietf.org/html/rfc2911

的問題是,我得到了一些從指定輸入盒的應用。我可以簡單地映射enum int值,或者使用數字來獲取枚舉值的常用方法是什麼?它甚至正式支持托盤數量?

我在RFC中找不到與輸出區對應的屬性。有沒有辦法做到這一點?

而最重要的問題是:打印機接口或多或少可靠?我發現人們詢問托盤的大多數線索最終都放棄了,因爲它們無法使其工作。

任何經驗,將不勝感激。

+4

*「和最重要的問題:是打印機接口或多或少地可靠?「*也許這個API是Sun/Oracle對環保主義的貢獻。 「拯救樹木!」 ;) –

+0

[使用屬性(紙盒控制,雙面打印等)使用javax.print庫打印](http://stackoverflow.com/questions/14328012/printing-with-attributestray-control-duplex- etc-using-javax-print-library) –

回答

2

這些屬性在javax.print.attribute.standard.MediaTray中定義。另請參閱Standard Attributes: Media

+0

正如問題中提到的,我已經找到了MediaTray。您發佈的文章包含大量有用的信息,例如如何繼承MediaTray的String屬性。但是,我找不到明確的信息來回答我的一個問題。 – box

+0

您提到應用程序通過編號指定了輸入區域。什麼應用?這個編號方案是否記錄在任何地方?如果不知道,可以將數字與'EnumSyntax#getValue()'進行比較,以獲得特定的MediaTray常量。 – trashgod

+1

直接檢查「MediaTray」常量可能更容易,例如「TOP」是0,「MIDDLE」是1等。 – trashgod

1

如果您想要使用真正的托盤編號而不是像TOP這樣的常規常量,那麼您將不得不做一些額外的編碼。 沒有列舉給定打印機的所有紙盤號碼的枚舉,因爲在編碼時將不知道有多少紙盤。 您需要查詢打印機服務獲取屬性類型爲Media.class的所有支持的屬性值。這會給你一個不同類型的列表。 打印結果,托盤應位於此列表中的某處。從這個列表中取出托盤非常重要,而不是自己構建它,因爲打印框架中的一些內部代碼與此鏈接。

注意: 打印API有一些與托盤打印有關的錯誤(特別是在UNIX上)。 要快速解決這些問題,投票: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7107175和/或 http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7107138

1

該如何打印爲 「紙盒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; 
    } 
}