本文介绍了Jasper报告 - 在PDF文档中设置作者属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法通过在从Java调用Jasper时设置参数来将Author属性设置为PDF文档。

Is there a way to set the Author property to a PDF document by setting a parameter when calling Jasper from Java.

这是我从Java生成Jasper报告的方式。

This is how I generate a Jasper report from Java.

      JasperPrint jasperPrint;
        String outFile = "39285923953222.pdf";
        HashMap hm = new HashMap();
        hm.put("ID",id);
        hm.put("FOOTER",Constants.FOOTER); // Set somehow a string for the author name

        Session session = this.sessionFactory.openSession();
        Connection con = session.connection();

        jasperPrint = JasperFillManager.fillReport(jasperPath + "myReport.jasper", hm, con);
        JasperExportManager.exportReportToPdfFile(jasperPrint, outPath + outFile);  


推荐答案

查看静态字段 http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/export/JRPdfExporterParameter.html\"rel =nofollow> JRPdfExporterParameter

使用而不是 JasperExportManager

示例:

JasperPrint jasperPrint = JasperFillManager.fillReport(jasperPath + "myReport.jasper", hm, con);

JRPdfExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE, outPath + outFile);
exporter.setParameter(JRPdfExporterParameter.METADATA_AUTHOR, "Adnan");
exporter.setParameter(JRPdfExporterParameter.METADATA_TITLE, "Title");
// ...
exporter.exportReport();

这篇关于Jasper报告 - 在PDF文档中设置作者属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 05:10