Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 设置PDF导出器的输出文件名_Java_Jasper Reports - Fatal编程技术网

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

Java 设置PDF导出器的输出文件名,java,jasper-reports,Java,Jasper Reports,我正在使用JasperReports 5.6 我使用PDFCreator生成pdf。 我的pdf已成功生成,但无法为该pdf文件设置名称 PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet(); printRequestAttributeSet.add(MediaSizeName.ISO_A4); PrintServiceAttributeSet printServiceAttr

我正在使用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_文件名,“d:/adc.pdf”)方法现在已弃用。

请告诉我如何设置文件名的解决方案

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

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

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

或者,您可以保持代码基本相同,但将
JRPrintServiceExporter
更改为一个。设置输出格式的新方法(现在,
setParameter
已被弃用)是构造一个,然后拜访您的出口商。

谢谢您的回复。但是先生,最初我们在阅读jasper报告中的区域语言时遇到了问题。我们选择使用上述代码。**JaspeExportManager.exportReportToPdfFile**将导出pdf,但对于区域语言,它将显示空白数据。@Vicky3D我可能不是处理区域设置问题的最佳人选,在这里的评论中也很难做到这一点。你应该解决这个问题,这样它就有了更广泛的受众,你可以包括更多的细节。