2011-04-05 74 views
4

有没有一种方法可以通过在从Java调用Jasper时设置参数来将Author属性设置为PDF文档。Jasper Report - 在PDF文档中设置Author属性

enter image description here

我这是怎么生成从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); 

回答

3

看看静态字段METADATA_AUTHORJRPdfExporterParameter
使用JRPdfExporter而不是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(); 
+0

谢谢@lschin,这就是我一直在寻找的。今天会试用。 – Adnan 2011-04-06 06:07:32

+1

请注意,这在较新版本中已被弃用,请参阅:http://stackoverflow.com/questions/24117878/jasperreports-5-6-jrxlsexporter-setparameter-is-deprecated – 2015-06-12 08:43:26

0

不知道这是正确的道路要走,但你可能想看看jasperPrint.getPropertyNames()jasperPrint.getPropertiesMap(),看看你在那里有任何author属性。

0

JRExporter变得根据this post在5.6弃用。 我这样做的:

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