简体   繁体   English

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

[英]how to print a PDF on an unmapped network printer in java?

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

Printer name given LIKE ( \\\\PSCPARKP01\\CP_P1_OKI20_4 ) 打印机名称为 LIKE(\\\\ PSCPARKP01 \\ CP_P1_OKI20_4)

Believe it or not Java is very, very bad at being able to do this. 信不信由你Java很难做到这一点。 One way I found to do this was to do a straight fileStream copy from file to folder. 我发现做到这一点的一种方法是从文件到文件夹直接进行fileStream复制。 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 有关此技术的许多注意事项

- 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. -我在这里使用的是Windows路径,如果您要运行的是Linux操作系统,那就完全不一样了,需要在打印机上安装支架等,这是另一个问题。

- IOUtils is the Apache commons library, you'll need the jar in your build path. -IOUtils是Apache commons库,在构建路径中需要jar。

- 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) -这实际上并不调用打印作业,它只是将文档复制到您的打印队列文件夹中,因此您将无法控制打印属性(例如页面范围,要打印的副本数等)

Ideally you should be using CUPS or IPP to do something like this. 理想情况下,您应该使用CUPS或IPP来执行类似的操作。

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

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