如何在java中未映射的网络打印机上打印PDF? [英] how to print a PDF on an unmapped network printer in java?

查看:97
本文介绍了如何在java中未映射的网络打印机上打印PDF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在java中的未映射的网络打印机上打印 PDF

How to print a PDF on an unmapped network printer in java?

打印机名称给予 LIKE(\\PSCPARKP01 \CP_P1_OKI20_4)

Printer name given LIKE ( \\PSCPARKP01\CP_P1_OKI20_4 )

推荐答案

信不信由Java非常非常不能做到这一点。我发现这样做的一种方法是从文件到文件夹执行直接的fileStream复制。类似于:

Believe it or not Java is very, very bad at being able to do this. One way I found to do this was to do a straight fileStream copy from file to folder. Something like:

File fileToPrint = new File("C://test/test.pdf");
File printFolder = new File("\\\\PSCPARKP01\\CP_P1_OKI20_4");
FileInputStream fis = new FileInputStream(fileToPrint);
FileOutputStream fos = new FileOutputStream(printFolder);
IOUtils.copy(fis, fos);
fis.close();
fos.close();

有关此技术的一些注意事项

A number of things to note about this technique

- 我在这里使用Windows路径,如果你在Linux机器上运行它是一个完全不同的故事,需要安装到打印机等等,这是一个不同的问题。

- I'm using windows paths here, if you're running off a linux box it's a completely different story, need a mount to the printer and etc, etc that's a different question.

- IOUtils是Apache commons库,你需要在构建路径中使用jar。

- IOUtils is the Apache commons library, you'll need the jar in your build path.

- 这个它实际上并不调用打印作业,只是将文档复制到打印队列文件夹中,因此您无法控制打印属性(如页面范围,要打印的份数等)

- this doesn't actually call a print job, it just copies the doc into your print queue folder, so you won't have control over print attributes (like page ranges, number of copies to be printed, etc)

理想情况下,您应该使用CUPS或IPP来做这样的事情。

Ideally you should be using CUPS or IPP to do something like this.

这篇关于如何在java中未映射的网络打印机上打印PDF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆