有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!


共 (1) 个答案

  1. # 1 楼答案

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

    例如:

    exporter.setParameter(JRPdfExporterParameter.PDF_VERSION, JRPdfExporterParameter.PDF_VERSION_1_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将被写入outputFile,因此您不需要调用printReport