开发者

Jasper Report - Set Author property in a PDF document

开发者 https://www.devze.com 2023-02-22 18:27 出处:网络
Is there a way to set the Author property to a PDF document by setting开发者_开发知识库 a parameter when calling Jasper from Java.

Is there a way to set the Author property to a PDF document by setting开发者_开发知识库 a parameter when calling Jasper from Java.

Jasper Report - Set Author property in a PDF document

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


Look at static field METADATA_AUTHOR in JRPdfExporterParameter.
Use JRPdfExporter instead of JasperExportManager.

Example :

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


Not sure if it is the right way to go, but you might want to look at jasperPrint.getPropertyNames() or jasperPrint.getPropertiesMap() and see if you have any author property in there.


JRExporter became deprecated in 5.6 according to this post. I got it to work doing this:

    ...
    final JRPdfExporter exporter = new JRPdfExporter();
    exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
    final SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
    configuration.setMetadataTitle(title);
    configuration.setMetadataAuthor(author);
    configuration.setMetadataCreator(creator);
    configuration.setMetadataSubject(subject);
    configuration.setMetadataKeywords(keywords);
    ...
0

精彩评论

暂无评论...
验证码 换一张
取 消