【问题标题】:How to change Jasper report Print name如何更改 Jasper 报告打印名称
【发布时间】:2018-07-01 02:35:33
【问题描述】:

当我发送jasper报告打印时,打印机显示文档名称为“jasper report-report name”(当有打印队列时,文档名称也为“jasper report”)。如何将其更改为其他名称?

【问题讨论】:

    标签: java jasper-reports


    【解决方案1】:

    样本:

        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();
    
    • 使用 iReport(编辑报告模板)

      您可以借助 name 属性在报告模板中设置报告名称:

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

    【讨论】:

    • 谢谢。正如您在 iReport 模板的 xml 中提到的那样,我编辑了 jasper 报告名称。然后报告名称已更改,但文档名称仍保持为碧玉报告。这意味着,打印对话框显示,文档名称=Jasper Report-我的名字。现在我想删除那个“Jasper 报告”文档名称。
    【解决方案2】:

    我偶然发现了这个,如果你在你想要的名字前加上一个'/',它会从打印名称中删除“JasperReports -”字符串。

    JasperPrint jrPrint = JasperFillManager.fillReport(jasperReport, params, getDataSource());
    if (reportName != null && reportName.length() > 0) {
            jrPrint.setName('/'+reportName);
        }
    

    【讨论】:

      【解决方案3】:

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

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

      第 404 行:

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

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多