Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 237
Débora Avatar asked Nov 18 '11 13:11

Débora


1 Answers

  • Using JasperReports API

    If you are using JasperReports API you should set report name with help of JasperPrint.setName(java.lang.String name) method.

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" ..>
    
like image 100
Alex K Avatar answered Sep 29 '22 08:09

Alex K