I am trying to print a PDF document.
I can see the job in the printer queue, and then I see it disappear, like if the printer had finished its job.
But the prob
I know it is a bit late to answer but since I had the same problem I think it can help others to post my solution.
I have faced this problem on Windows (7), but not on Linux (Fedora), so my first action was to check the drivers setup.
Then, I saw that PDFs are not native processed by many printers. It is accepted but nothing is printed. From this, several solutions can be chosen:
I chose solution 2 and it works like a charm. The nice thing in this is that it also uses PrintService, with attributes, so you can deal with pages, printer trays and many options.
Here is a part of my code:
private boolean print(PrintService printService, InputStream inputStream, PrintRequestAttributeSet attributes)
throws PrintException {
try {
PDDocument pdf = PDDocument.load(inputStream);
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintService(printService);
job.setPageable(new PDFPageable(pdf));
job.print(attributes);
pdf.close();
} catch (PrinterException e) {
logger.error("Error when printing PDF file using the printer {}", printService.getName(), e);
throw new PrintException("Printer exception", e);
} catch (IOException e) {
logger.error("Error when loading PDF from input stream", e);
throw new PrintException("Input exception", e);
}
return true;
}
Hope this helps.