简体   繁体   English

使用Java时防止Windows打开打印对话框

[英]Prevent windows from opening the printing dialog when using java

I am trying to make a program that prints a page with several strings, this works just fine but the problem is that it asks me everytime what printer I want to use and this must be transparent for the user (meaning it should print on their default printer without showing the "select device" thingy), so far I've not been able to find a way to do this with java and I don't even know if it is possible, as far as I'm aware you cannot set windows to behave like that either, but I might be mistaken. 我正在尝试制作一个程序,该程序可以打印带有多个字符串的页面,这很好用,但是问题是它每次都问我要使用哪种打印机,并且该打印机必须对用户透明(这意味着它应该使用默认打印机进行打印)打印机而没有显示“选择设备”),到目前为止,我还无法找到使用java进行此操作的方法,据我所知您无法设置,甚至我都不知道是否可能Windows要么表现得像那样,但我可能会误会。

By the way, the version is windows 7 if that gives any sort of information at all. 顺便说一句,如果可以提供任何类型的信息,则版本为Windows 7。

To fix this in Windows 7, click Start and select the option Devices and Printers. 要在Windows 7中解决此问题,请单击“开始”,然后选择选项“设备和打印机”。 Under Printers and Faxes, right-click the printer you want to make the default, and select Set as default printer. 在“打印机和传真”下,右键单击要用作默认打印机的打印机,然后选择“设为默认打印机”。 I think this can solve the issue. 我认为这可以解决问题。

Edit : If this doesn't work, make use of print API in java such as : import javax.print.PrintServiceLookup; PrintService service = PrintServiceLookup.lookupDefaultPrintService(); 编辑:如果这不起作用,请使用java中的打印API,例如: import javax.print.PrintServiceLookup; PrintService service = PrintServiceLookup.lookupDefaultPrintService(); import javax.print.PrintServiceLookup; PrintService service = PrintServiceLookup.lookupDefaultPrintService();

Java docs : Locates the default print service for this environment. Java文档:找到此环境的默认打印服务。 This may return null. 这可能返回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. 如果没有明显可识别的平台本机默认打印服务,则默认设置是第一个以实现相关的方式定位的默认服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM