gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 12:39:10 24 4
gpt4 key购买 nike

我正在使用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关于您的导出商。

关于java - 设置 PDF 导出器的输出文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25280377/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com