使用 java 时阻止 windows 打开打印对话框

Prevent windows from opening the printing dialog when using java

我正在尝试制作一个程序来打印包含多个字符串的页面,这工作得很好,但问题是每次我想使用什么打印机时它都会询问我,这对用户来说必须是透明的(意思是它应该在他们的默认打印机上打印而不显示 "select device" 东西),到目前为止我还没有找到使用 java 来做到这一点的方法,我什至不知道这是否可能,据我所知,您也不能将 windows 设置为那样,但我可能弄错了。

顺便说一下,版本是 windows 7 如果它提供了任何类型的信息。

要在 Windows 7 中修复此问题,请单击“开始”和 select 选项“设备和打印机”。在“打印机和传真”下,右键单击要设置为默认打印机的打印机,然后 select 设置为默认打印机。我认为这可以解决问题。

编辑:如果这不起作用,请在 java 中使用 print API 例如: import javax.print.PrintServiceLookup; PrintService service = PrintServiceLookup.lookupDefaultPrintService();

Java docs : Locates the default print service for this environment. This may return null. If multiple lookup services each specify a default, the chosen service is not precisely defined, but a platform native service, rather than an installed service, is usually returned as the default. If there is no clearly identifiable platform native default print service, the default is the first to be located in an implementation-dependent manner.