How to detect "Save as PDF ..." was selected from AWT PrinterJob on OS X

I have the following code that shows my own print dialog in my java application.

PrinterJob job = PrinterJob.getPrinterJob(); PrintRequestAttributeSet atts = new HashPrintRequestAttributeSet(); atts.add(DialogTypeSelection.NATIVE); if (job.printDialog(atts)) { PrintService newlyUsedService = job.getPrintService(); DocPrintJob docJob = newlyUsedService.createPrintJob(); // print the passed javax.print.SimpleDoc object. docJob.print(simpleDoc, atts); } 

This code works great when choosing a printer and clicking the "Print" button, but it does not work when the user selects any option from the "PDF" menu in the lower left corner. The getPrintService method returns the last printer selected ( Lillith from the screenshot) when one of the options in the "PDF" menu is selected.

Screenshot of OS X print dialog

Can anyone suggest what needs to be done in order to detect when “Save as PDF ...” was selected in the print dialog and respond accordingly.

+7
source share
1 answer

Have you tried to add a print job listener? Just read about it now, I hope this helps:

Print Job Listener

0
source

All Articles