设置PDF导出器的输出文件名

我使用的是JasperReports 5.6
我使用PDFCreator生成pdf。
我的pdf生成成功,但我无法为该PDF文件设置名称。

PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet(); printRequestAttributeSet.add(MediaSizeName.ISO_A4); PrintServiceAttributeSet printServiceAttributeSet = new HashPrintServiceAttributeSet(); printServiceAttributeSet.add(new PrinterName("PDFCreator", null)); JRPrintServiceExporter exporter = new JRPrintServiceExporter(); exporter.setExporterInput(new SimpleExporterInput(tempFileName)); SimplePrintServiceExporterConfiguration configuration = new SimplePrintServiceExporterConfiguration(); configuration.setPrintRequestAttributeSet(printRequestAttributeSet); configuration.setPrintServiceAttributeSet(printServiceAttributeSet); configuration.setDisplayPageDialog(false); configuration.setDisplayPrintDialog(false); exporter.setConfiguration(configuration); exporter.exportReport(); 

我的pdf名称是使用该PDFCreator工具设置的
我想将名称传递给该pdf文件。
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "d:/adc.pdf"); 方法现已弃用。
请告诉我如何设置该文件名的解决方案

我认为没有办法将文件名传递给PDFCreator,因为整个想法是它是一个虚拟打印机。 因此,对于发送文档的程序,它可能在某个地方的物理打印机上打印,因此输出文件名将无关紧要。

每当我需要将报告输出为PDF时,我使用JasperExportManager ,这是一个更简单的解决方案。 exportReportToPdfFile方法接受输出文件路径作为字符串。 例:

 JasperPrint filledReport = JasperFillManager.fillReport("report.jrxml", params); JasperExportManager.exportReportToPdfFile(filledReport, "report.pdf"); 

或者,您可以保持代码大致相同,但将JRPrintServiceExporter更改为JRPdfExporter 。 设置输出格式的新方法(现在不推荐使用setParameter )是构造ExporterOutput ,然后在导出setExporterOutput上调用setExporterOutput