Karthick
Karthick

Reputation: 143

How can I change the change Jasper Reports PDF version during runtime

How do I set the export pdf version at run time in Jasper?

Upvotes: 2

Views: 3474

Answers (1)

GenericJon
GenericJon

Reputation: 8986

On your instance of JRPdfExporter, call the method setParameter and use the constants defined in JRPdfExporterParameter to set the version appropriately.

Example:

exporter.setParameter(JRPdfExporterParameter.PDF_VERSION, JRPdfExporterParameter.PDF_VERSION_1_2);

There are constants for versions 1.2 through 1.7.

For your code, the solution would be something like this:

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();

The pdf will then be written to outputFile, so you won't need to call printReport.

Upvotes: 4

Related Questions