Skip to content
Advertisement

How to change Jasper report Print name

When I send the jasper report to print, the printer shows the document name as “jasper report-report name” (When there is a printing que, document name is also “jasper report” ). How can I change it to another name?

Advertisement

Answer

The sample:

    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" ..>
    
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement