Java 如何在运行时更改Jasper Reports PDF版本

Java 如何在运行时更改Jasper Reports PDF版本,java,jasper-reports,Java,Jasper Reports,如何在Jasper中设置运行时的导出pdf版本?在您的JRPdfExporter实例上,调用方法setParameter,并使用JRPdfExporterParameter中定义的常量来适当设置版本 例如: exporter.setParameter(JRPdfExporterParameter.PDF\u版本,JRPdfExporterParameter.PDF\u版本\u 1\u 2) 版本1.2到1.7有一些常量 对于您的代码,解决方案如下: JasperPrint print = Jas

如何在Jasper中设置运行时的导出pdf版本?

在您的
JRPdfExporter
实例上,调用方法
setParameter
,并使用
JRPdfExporterParameter
中定义的常量来适当设置版本

例如:

exporter.setParameter(JRPdfExporterParameter.PDF\u版本,JRPdfExporterParameter.PDF\u版本\u 1\u 2)

版本1.2到1.7有一些常量

对于您的代码,解决方案如下:

JasperPrint print = JasperFillManager.fillReport(jasperReport, param, con);
File outputFile = new File("[Your destination filename goes here]"); 
JRPdfExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE, outputFile);
exporter.setParameter(JRPdfExporterParameter.PDF_VERSION, JRPdfExporterParameter.PDF_VERSION_1_2);
exporter.exportReport();

然后,pdf将被写入
输出文件
,因此您不需要调用
打印报告

我的代码如下:JasperPrint print=JasperFillManager.fillReport(jaspereport,param,con);打印报告(数据、请求、打印);在此之后,我必须为exporter创建对象并设置参数?@Karthick我已经用一个特定的代码示例更新了我的答案。希望有帮助。请在下面的链接上提供帮助:。多谢。