简体   繁体   English

如何使用java代码添加可用的网络打印机?

[英]How to add an available network printer using java code?

I would like to get the list of available network printers, and allow users to install (add) a selected printer on their pc using a JButton.我想获取可用网络打印机的列表,并允许用户使用 JButton 在他们的电脑上安装(添加)选定的打印机。

I have searched the net and did find a java api called java printer api but this didn't help me.我在网上搜索过,确实找到了一个名为 java printer api 的 java api,但这对我没有帮助。

Any suggestions ?有什么建议 ?

As you have probably realized, the standard Java Print service API is for printing documents from a Java application.您可能已经意识到,标准的 Java 打印服务 API用于从 Java 应用程序打印文档。 It works by interacting with an existing printer or print service provided by the host system.它通过与主机系统提供的现有打印机或打印服务交互来工作。 It does not address the concerns of setting up or configuring printers or print services.它没有解决设置或配置打印机或打印服务的问题。

I would like to get the list of available network printers, and allow users to install (add) a selected printer on their PC using a JButton .我想获取可用网络打印机的列表,并允许用户使用JButton在他们的 PC 上安装(添加)选定的打印机。

The Java printing APIs don't provide that functionality. Java 打印 API 不提供该功能。

So there is no way to automate the install process?那么有没有办法使安装过程自动化? Execute a batch script maybe?也许执行批处理脚本?

If it is possible to automate printer installation, discovery, configuration (or what have you) using a shell script or batch file that can be run by an unprivileged user, then it is possible (actually simple) to get Java to run the script.如果可以使用可由非特权用户运行的 shell 脚本或批处理文件来自动化打印机安装、发现、配置(或您拥有的东西),那么就有可能(实际上很简单)让 Java 运行脚本。

Writing that script is likely the hard part, and it is not a Java programming problem.编写该脚本可能是困难的部分,它不是 Java 编程问题。 And if you can't write / find a script to do this, then your chances of doing printer setup from a Java program are about zero.如果您无法编写/找到执行此操作的脚本,那么您从 Java 程序进行打印机设置的机会几乎为零。 While it may be technically possible to do the task in Java, it is (IMO) not worth the development effort to do it that way.虽然在技术上可以用 Java 完成这项任务,但 (IMO) 不值得以这种方式进行开发工作。

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

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