8

I have the following code that shows a native 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 fine when a printer is selected and the Print button is clicked, but it does not work when the user selects any option from the “PDF” menu at the bottom left. The getPrintService method returns the last selected printer (Lillith from the screenshot) when one of the options in the "PDF" menu are selected.

Screenshot of OS X print dialog

Could anyone suggest what should be done to detect when “Save as PDF…” was selected in the print dialog and respond accordingly.

1 Answers1

1

Have you tried adding a Print Job Listener? Just read up on it now, I hope it will be of some help:

Print Job Listener

James
  • 349
  • 1
  • 6
  • 17