问题描述
我正在使用 JasperReports 5.6
我使用PDFCreator生成pdf。
我的pdf生成成功,但我无法设置名称到该PDF文件。
I am using JasperReports 5.6
I generate pdf using PDFCreator.
My pdf is generated successfully, but i can't set name to that PDF file.
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);
方法现在弃用。
请告诉我解决方法如何设置文件名
My pdf name are set using that PDFCreator tool
I want to pass the name to that pdf file.
Since exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "d:/adc.pdf");
method is now deprecated.
Please tell me solution how to set that out file name
推荐答案
我不知道认为有一种方法可以将文件名传递给PDFCreator,因为整个想法是它是一个虚拟打印机。因此,对于发送文档的程序,它可能正在某个物理打印机上打印,因此输出文件名将无关紧要。
I don't think there's a way to pass a file name to PDFCreator, because the whole idea is that it is a virtual printer. So to the program that sending the document, it could be being printed on a physical printer somewhere, hence an output file name would be irrelevant.
每当我需要输出报告时作为PDF我使用 JasperExportManager
,这是一个更简单的解决方案。 exportReportToPdfFile
方法接受输出文件路径作为字符串。示例:
Whenever I need to output reports as PDFs I use JasperExportManager
, which is a much simpler solution. The exportReportToPdfFile
method accepts the output file path as a string. Example:
JasperPrint filledReport = JasperFillManager.fillReport("report.jrxml", params);
JasperExportManager.exportReportToPdfFile(filledReport, "report.pdf");
或者,您可以保持代码大致相同但更改 JRPrintServiceExporter
到。设置输出格式的新方法(现在 setParameter
已弃用)是构造然后调用出口商。
Alternatively, you can keep your code largely the same but change your JRPrintServiceExporter
to a JRPdfExporter
. The new way to set the output format (now that setParameter
is deprecated) is to construct an ExporterOutput
and then call setExporterOutput
on your exporter.
这篇关于设置PDF导出器的输出文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!