Jasper Report - Set Author to PDF

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

enter image description here

This is how I create 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); 
+4
source share
3 answers

Look at the static field METADATA_AUTHOR in the 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(); 
+3
source

Not sure if this is the right way, but you can look at jasperPrint.getPropertyNames() or jasperPrint.getPropertiesMap() and see if you have any property of the author.

0
source

JRExporter is deprecated in 5.6 according to this post . I got this for work:

  ... 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
source

Source: https://habr.com/ru/post/1346741/


All Articles