PDF PrinterJob Gets Job Status

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?

+6
source share
1 answer
 javafx.print Enum PrinterJob.JobStatus java.lang.Object java.lang.Enum<PrinterJob.JobStatus> javafx.print.PrinterJob.JobStatus public static PrinterJob.JobStatus[] values() Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows: for (PrinterJob.JobStatus c : PrinterJob.JobStatus.values()) System.out.println(c); 
+2
source

Source: https://habr.com/ru/post/978172/


All Articles