I have a problem with PDF printing using java. I know that Java does not support PDF printing natively, because java does not have PDF rendering. Therefore, to solve this problem, I use the PDFRenderer library, and here is an example of printing it:
File f = new File("myfile.pdf"); FileInputStream fis = new FileInputStream(f); FileChannel fc = fis.getChannel(); ByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size()); PDFFile pdfFile = new PDFFile(bb); PDFPrintPage pages = new PDFPrintPage(pdfFile); PrinterJob pjob = PrinterJob.getPrinterJob(); PageFormat pf = PrinterJob.getPrinterJob().defaultPage(); pjob.setJobName(f.getName()); pjob.setPrintService(mPrintService); Book book = new Book(); book.append(pages, pf, pdfFile.getNumPages()); pjob.setPageable(book); pjob.print();
It works fine, but I need to somehow get the status of my printer job. I need to know when my work with the printer was finished, and I can start with it. The Java API has a good solution with DocPrintJob and PrintJobListener, but I need to use PrinterJob for my PDF printing. So, how can I listen to job status from my PrinterJob, like in DocPrintJob?
source share