当我发送Jasper报告进行打印时,打印机显示文档名称为“jasper报告-报告名称”(当有打印队列时,文档名称也是“jasper报告”)。我该如何将其更改为另一个名称?
样例:
JasperReport jasperReport = JasperCompileManager.compileReport(reportSource);
JasperPrint jrPrint = JasperFillManager.fillReport(jasperReport, params, getDataSource());
if (reportName != null && reportName.length() > 0) {
jrPrint.setName(reportName);
}
PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
printRequestAttributeSet.add(MediaSizeName.ISO_A4);
PrintServiceAttributeSet printServiceAttributeSet = new HashPrintServiceAttributeSet();
printServiceAttributeSet.add(new PrinterName("PDFCreator", null));
JRPrintServiceExporter exporter = new JRPrintServiceExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jrPrint);
exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, printRequestAttributeSet);
exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, printServiceAttributeSet);
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.TRUE);
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.TRUE);
exporter.exportReport();
You can set report name in report template with help of name
attribute:
<jasperReport .. name="Sample report name to print" ..>
JasperPrint jrPrint = JasperFillManager.fillReport(jasperReport, params, getDataSource());
if (reportName != null && reportName.length() > 0) {
jrPrint.setName('/'+reportName);
}
printRequestAttributeSet将覆盖没有前缀(“JasperReports -”)的setJobName。 我正在使用japserreports-6.14
printRequestAttributeSet.add(
new JobName("My software", null));
我和你一样遇到了同样的问题,很高兴我想我找到了解决问题的方法。
第404行:
printerJob.setJobName("JasperReports - " + jasperPrint.getName());
所以显然我们只需要编辑这行代码(删除“JasperReports -”+“”部分),然后编译它并使用我们的自定义jar分发包。
我现在唯一的问题是我还没有测试过它,因为我从未编译过源代码包。当我弄清楚如何编译和测试时,我会更新我的答案。