如何更改Jasper报表的打印名称

5
当我发送Jasper报告进行打印时,打印机显示文档名称为“jasper报告-报告名称”(当有打印队列时,文档名称也是“jasper报告”)。我该如何将其更改为另一个名称?
4个回答

8

样例:

    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();
  • Using iReport (editing report template)

    You can set report name in report template with help of name attribute:

    <jasperReport .. name="Sample report name to print" ..>
    

1
谢谢。我按照您在iReport模板的XML中提到的方式编辑了Jasper报表名称。然后报表名称已更改,但文档名称仍为Jasper报表。这意味着打印对话框显示文档名称= Jasper Report-我的给定名称。现在我想删除“Jasper报表”文档名称。 - Débora

1
我无意中发现了这个方法,如果你在想要的名称前面加上'/',它将从打印名称中移除“JasperReports -”字符串。
JasperPrint jrPrint = JasperFillManager.fillReport(jasperReport, params, getDataSource());
if (reportName != null && reportName.length() > 0) {
        jrPrint.setName('/'+reportName);
    }

0

printRequestAttributeSet将覆盖没有前缀(“JasperReports -”)的setJobName。 我正在使用japserreports-6.14

printRequestAttributeSet.add(
 new JobName("My software", null));

0

我和你一样遇到了同样的问题,很高兴我想我找到了解决问题的方法。

https://github.com/TIBCOSoftware/jasperreports/blob/master/jasperreports/src/net/sf/jasperreports/engine/export/JRPrintServiceExporter.java

第404行:

printerJob.setJobName("JasperReports - " + jasperPrint.getName());

所以显然我们只需要编辑这行代码(删除“JasperReports -”+“”部分),然后编译它并使用我们的自定义jar分发包。

我现在唯一的问题是我还没有测试过它,因为我从未编译过源代码包。当我弄清楚如何编译和测试时,我会更新我的答案。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接