开发者

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

How to print a PDF on an unmapped network printer开发者_如何学编程 in java?

Printer name given LIKE ( \\PSCPARKP01\CP_P1_OKI20_4 )


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

- 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 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)

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜