我有以下代码在我的 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 ( Lillith
from the screenshot) when one of the options in the "PDF" menu are selected.
任何人都可以建议应该做些什么来检测在打印对话框中选择“另存为 PDF…”并做出相应的响应。