7

我有以下代码在我的 java 应用程序中显示本机打印对话框。

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 ( Lillithfrom the screenshot) when one of the options in the "PDF" menu are selected.

OS X 打印对话框的屏幕截图

任何人都可以建议应该做些什么来检测在打印对话框中选择“另存为 PDF…”并做出相应的响应。

4

1 回答 1

0

您是否尝试过添加打印作业侦听器?现在就阅读它,我希望它会有所帮助:

打印作业监听器

于 2013-04-12T00:02:39.710 回答