2011-04-05 76 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); 
    ...