Java – how to detect that “save as PDF…” is selected from AWT printerjob on OS X

I have the following code to display the native Print dialog box 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 when you select a printer and click the print button, but it does not work when the user selects any option from the PDF menu in the lower left corner When an option in the "PDF" menu is selected, the getprintservice method returns the last selected printer (lillith in the screenshot)

Anyone can suggest to detect and respond when "save as PDF..." is selected in the print dialog box

Solution

Have you tried to add a print job listener? Now read it and I hope it will help:

Print Job Listener

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>