How to print a PDF on an unmapped network printer in java?
Printer name given LIKE ( \\PSCPARKP01\CP_P1_OKI20_4 )
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.