How to change Jasper report Print name


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?




3 Answers
3



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();



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


name


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





Thank you. I edited the jasper repor name as you mentioned in the xml of iReport template. Then the report name was changed but still Document name remains as jasper report. That means, the printing dialog shows, document name=Jasper Report-My given name. now I want to remove that "Jasper report"document name.
– Débora
Nov 21 '11 at 13:39





Does <jasperReport accept variables like date?
– zygimantus
Oct 26 '16 at 9:51


<jasperReport





I believe, no. But you can use Java code
– Alex K
Oct 26 '16 at 10:03




I've found this by accident, if you put a '/' before the name you want, it will remove the "JasperReports -" string from the print name.


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





That does not work for me, Paulo. JR version 5.6.0
– Jens Kreidler
Feb 19 '15 at 15:19



I was having the same problem as you and I'm glad that I think I found a way to work on the problem.



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



Line 404:


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



So apparently we just need to edit this line of code (remove the " "JasperReports - " + " part) and compile it and use our custom jar distribution package.



My only problem right now is that I have not tested it yet because I have never compiled a package from source. I will update my answer when I have figured out how to compile and tested it.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

List of Kim Possible characters

Audio Livestreaming with Python & Flask

NSwag: Generate C# Client from multiple Versions of an API