有没有办法通过在从Java调用Jasper时设置参数来将Author属性设置为PDF文档。
这是我从Java生成Jasper报告的方式。
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);
答案 0 :(得分:3)
查看METADATA_AUTHOR中的静态字段JRPdfExporterParameter。
使用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();
答案 1 :(得分:0)
不确定这是否是正确的方法,但您可能需要查看jasperPrint.getPropertyNames()
或jasperPrint.getPropertiesMap()
,看看您是否有任何作者属性。
答案 2 :(得分:0)
根据this post,JRExporter在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);
...