A logo showing the text blog.marcnuri.com
Español
Home»Java»Choosing a printer programmatically in Jasper Reports

Recent Posts

  • Fabric8 Kubernetes Client 7.2 is now available!
  • Connecting to an MCP Server from JavaScript using AI SDK
  • Connecting to an MCP Server from JavaScript using LangChain.js
  • The Future of Developer Tools: Adapting to Machine-Based Developers
  • Connecting to a Model Context Protocol (MCP) Server from Java using LangChain4j

Categories

  • Artificial Intelligence
  • Front-end
  • Go
  • Industry and business
  • Java
  • JavaScript
  • Legacy
  • Operations
  • Personal
  • Pet projects
  • Tools

Archives

  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • August 2024
  • June 2024
  • May 2024
  • April 2024
  • March 2024
  • February 2024
  • January 2024
  • December 2023
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
  • February 2020
  • January 2020
  • December 2019
  • October 2019
  • September 2019
  • July 2019
  • March 2019
  • November 2018
  • July 2018
  • June 2018
  • May 2018
  • April 2018
  • March 2018
  • February 2018
  • December 2017
  • July 2017
  • January 2017
  • December 2015
  • November 2015
  • December 2014
  • March 2014
  • February 2011
  • November 2008
  • June 2008
  • May 2008
  • April 2008
  • January 2008
  • November 2007
  • September 2007
  • August 2007
  • July 2007
  • June 2007
  • May 2007
  • April 2007
  • March 2007

Choosing a printer programmatically in Jasper Reports

2007-03-22 in Java / Legacy tagged BI / Jasper / Jasper Reports / Java / Reports / Swing by Marc Nuri | Last updated: 2025-01-13
Versión en Español

Jasper Reports is, in my opinion, one of the best reporting engines available for Java. It’s powerful, flexible, and open-source! The official project page offers ample documentation to help you build both simple and advanced reports. For additional guidance, you can purchase guides or technical support from JasperSoft.

In this post, we’ll explore how to programmatically choose a printer and print reports using Jasper Reports. Let’s check an example that demonstrates how to achieve this.

JasperReportsPrinter.java
public class JasperReportsPrinter {
  public void printReport() {
    // Fill the JasperPrint object with data
    JasperPrint print = JasperFillManager.fillReport(
        JasperReportsPrinter.class.getResource("/classpath/yourReport.jasper").getPath(),
        new HashMap(), new YourReportDataSource());
    PrinterJob job = PrinterJob.getPrinterJob();
    // Retrieve available print services
    PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
    int selectedService = 0;

    // Find a print service by name that matches our criteria
    for (int i = 0; i < services.length;i++) {
      if (services[i].getName().toUpperCase().contains("Your printer's name")) {
        // Select the first service that matches our criteria
        selectedService = i;
        break;
      }
    }
    job.setPrintService(services[selectedService]);

    // Set up print attributes
    PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
    printRequestAttributeSet.add(MediaSize.findMedia(4, 4, MediaPrintableArea.INCH));
    printRequestAttributeSet.add(new Copies(1));

    // Configure the JRPrintServiceExporter
    JRPrintServiceExporter exporter = new JRPrintServiceExporter();
    exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
    /* We set the selected service and pass it as a parameter */
    exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE,
        services[selectedService]);
    exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET,
        services[selectedService].getAttributes());
    exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET,
        printRequestAttributeSet);
    exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG,
        Boolean.FALSE);
    exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG,
        Boolean.TRUE);

    // Export the report to the printer
    exporter.exportReport();
  }
}

Key Points

  1. Generate the JasperPrint Object:
    The JasperPrint object is the core representation of your filled report. This step involves providing the path to the .jasper file and passing the required data source.
  2. Retrieve Available Printers:
    Use PrintServiceLookup.lookupPrintServices() to fetch the list of available printers. You can then iterate through the list to find a printer by name.
  3. Configure Print Attributes:
    Use the PrintRequestAttributeSet to set attributes like the paper size (e.g., A4) and the number of copies.
  4. Set Up the Exporter:
    The JRPrintServiceExporter is configured with the selected print service and attributes. It handles the actual communication with the printer.
  5. Trigger the Printing:
    The exportReport() method sends the report to the printer. You can optionally suppress the print and page dialog boxes.

Conclusion

With the code above, you can efficiently choose a printer programmatically and print reports using Jasper Reports. This approach not only streamlines the printing process but also provides the flexibility to customize printer settings dynamically. Whether you're developing enterprise applications or small-scale projects, this method ensures seamless integration with your printing workflows.

Twitter iconFacebook iconLinkedIn iconPinterest iconEmail icon

Comments in "Choosing a printer programmatically in Jasper Reports"

  • Avatar for Juriy
    Juriy
    2007-03-22 14:59
    Hi!
    Hi Mark!
    Nice code!
    I'm writing some articles about JasperReports library on http://voituk.kiev.ua (unfortunately on Russian). Can I post a translated version of this entry on my blog (of course, i'll post a link to this page)? Plz reply on email.
  • Avatar for Juriy
    Juriy
    2007-03-22 15:09
    Just one more question: when i've executed the code, i've got a "Printer Setup" window. That's a bit annoying, cause we've already selected the printer and provided all information needed for printer.
    Is there a way to get rid of this window?
  • Avatar for Marc Nuri
    Marc Nuri
    2007-03-22 15:15
    To remove the printer selection dialog, you just have to change
    exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.TRUE);
    to
    exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.FALSE);
  • Avatar for Joerg
    Joerg
    2007-06-08 11:04
    Hello Marc,
    I have to solve a Problem like this, but don't know how. Cause I'm a beginner with Jasper and iReport I don't understand where to insert your code in my jrxml... and btw, I know exactly which printer I want to use, so do I have to search for the services...
    Please, if you can/want help look at my request here: http://www.netbeans-forum.de/viewtopic.php?p=2767
    Thank you!
  • Avatar for Marc Nuri
    Marc Nuri
    2007-06-08 11:16
    Hi, I've read your translation of http://www.netbeans-forum.de/viewtopic.php?p=2767 but don't really understand what you need to do.
    The article shows the code you need to run/print a report from a java program. In your request, you talk about inserting the code in your report source which you CAN'T.
    You must insert the code in your java application where you are calling the report to be printed. If you are running the report directly from iReport you will have to choose the printer manually.
    Then you include another issue, which is printing one page to one tray and another to the second tray of the printer. Tray selection in java is not very well implemented, in fact, java printing API is not very good and causes some trouble across different platforms (things don't work the same in windows and in Linux for example). I would approach your problem by creating two different reports and then print them separately.
    Finally, the search for the services is necessary (someone correct me if I'm wrong), because you need a way to grab your service and there's no such thing as PrintService.getInstance(String serviceName);
    So even it is time-consuming it is necessary. Maybe you could store your service in a variable for future use so you don't have to look up the service each time.
  • Avatar for Joerg
    Joerg
    2007-06-08 13:30
    Thanks for the quick answer.
    It's right, I tried to insert the code into my report.
    Inserting it in the Java App is not possible for me, because the Java App is not mine and can't be changed.
    So I try to find out, how it may possible to commit control code with the Report so the printer changes the tray... If necessary with another app between report (Jasper) and Printer...
  • Avatar for cesar
    cesar
    2007-06-14 16:45
    Hi, I have a little problem. I'm using the code on my application. When I run the application on jdeveloper works great, I can print the report, but when I run the application in tomcat, at the moment I press the print button nothing happens, no print dialog appears and stays that way until the application times out. Any tip on what's happening?
    Thanks
  • Avatar for Marc Nuri
    Marc Nuri
    2007-06-15 09:04
    Hi Cesar.
    You should be more explicit with your problem. Is the application running in JDeveloper the same as the one running in Tomcat?
    I suppose that in JDeveloper you're running a standard j2se application and in tomcat you're trying to print from your webapplication. The problem with this code is that webApplications are run from the server and so you're program will be trying to print in the server and not in the client machine.
  • Avatar for cesar
    cesar
    2007-06-15 16:55
    Thanks for answering. You're right I didn't explain my problem very well. I'm running the same application with jdeveloper and tomcat. The application generates the report inside an iframe and I used javascript to print the report inside the iframe. But I didn't like that the printed report showed the url, date and page number. So I was looking for a way to print the report just with the information I want without any additional information the web browser could add. Is ther a way to solve this?
  • Avatar for Marc Nuri
    Marc Nuri
    2007-06-18 08:27
    To solve your problem you have to build a servlet to print your generated reports.

    Quick Google query:
    JASPERREPORTS SERVLET

  • Avatar for cesar
    cesar
    2007-06-19 01:17
    Thanks, I'll look for it. Keep up the good work.
  • Avatar for bm
    bm
    2007-07-14 00:41

    Hello, I came across your post and it was extremely helpful in setting up my jasper servlet to allow for printing reports directly to a client's default printer once they've ran the reports.

    I'm having one problem ... the servlet seems to be always selecting the default printer of the server and not the default printer of the client whose actually running the report via the web.

    Does the printServiceLookup.lookupDefaultPrintService() function only pool those printers on the server?

    If so is there a way to get the servicelookup to poll the client's printer list and select their default printer?

    Here's my code ..

    PrinterJob job = PrinterJob.getPrinterJob();
    /* Create an array of PrintServices */
    PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
    PrintService default_service = PrintServiceLookup.lookupDefaultPrintService();
    int selectedService = 0;
    /* Scan found services to see if anyone suits our needs */
    for(int i = 0; i < services.length;i++) {
      if(services[i].getName().toUpperCase().equals(default_service.getName().toUpperCase())) {
        selectedService = i;
      }
    }
    job.setPrintService(services[selectedService]);
    PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
    printRequestAttributeSet.add(MediaSizeName.NA_LETTER);
    printRequestAttributeSet.add(new Copies(1));
    JRPrintServiceExporter exporter;
    exporter = new JRPrintServiceExporter();
    exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
    /* We set the selected service and pass it as a paramenter */
    exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE, services[selectedService]);
    exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, services[selectedService].getAttributes());
    exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, printRequestAttributeSet);
    exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
    exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.FALSE);
    exporter.exportReport();
    
    thanks for your help!
  • Avatar for Marc Nuri
    Marc Nuri
    2007-07-16 08:17
    As you say in your post, your report is run from a servlet. Servlets are always run in the server which holds them.

    So what happens is that the server is the computer who is printing the report and not the client.

    To print the report from the client's computer you will have to implement another solution. I can think of a couple: run a java aplet which prints an input stream (not very elegant these days.) Export your report to html and let the servlet output an OutputStream, then print from clients computer and select the printer with javascript. Or export the report to pdf...

    Hope it helps.
  • Avatar for bm
    bm
    2007-07-16 20:05
    Thank you for your response.
    I was thinking that was the case. I would export the report to a PDF or HTML, but I'm trying to simulate batch reporting with the servlet. The servlet is iterating through a loop and running multiple reports one after another. A printer has to be installed on a server for the server to print for it correct? Does java have the functionality built in to resolve a printer on the network if you have the printer's network name?
  • Avatar for Marc Nuri
    Marc Nuri
    2007-07-17 07:25

    Strange servlet yours... ;)

    PrintServiceLookup.lookupPrintServices(null, null);

    Will list all of the printers installed or accesible from your server. So if your os has the network printer installed, your servlet will list that printer even if it is a network printer.

    If you want to install or resolve the printer during runtime, I don't know if java is capable of resolving the printer with non native methods (but I don't think so, java printing is very weak). The solution will be to implement any native method or run an os command. In windows "NET USE [port:] [\\computer\printer [password | ?]]".

    Hope it helps.

  • Avatar for Rishiraj Barthakur
    Rishiraj Barthakur
    2007-09-12 09:05

    Printing Problem in Client Machines(Printing Permission)

    Hello, I came across a problem. I could display my report in applet which I have created with iReport tool. The problem is at the time of printing on the client machine is gives a error dialog box comes "Error In Printing". I have to configure my java.policy file with some extra code for printing permission. So this has become a problem. If I give report online how can I configure infinite clients on the web for pritning the report. Is there any other way to do so without configuring the java.policy file in the client machine?

    Please Help..

    Thanks in Advance

  • Avatar for domino
    domino
    2007-09-14 08:54
    hi.
    I need some help with the report I've made.
    The case is this, I have to print a six page report with subreports in a whole master..
    However, I will only be able to correctly layout the subreports on the whole 6-page layout if I customized the page height(e.i. totalling a 6-page customized height).
    I used page break to separate subreports on each pages.
    It worked.However, when viewing the whole report, what I viewed was the whole customized height I've made.printing was fine.
    It was the viewing that concerns me.
    What I wanted to view really was the part of the page that is to be printed not the whole long page I've made.
    Can u suggest something to address my problem or is there any other way to layout subreports separately on multiple page format?
  • Avatar for paulo
    paulo
    2007-10-02 19:58
    Marc, the search for the services is NOT necessary.

    You can do:
    PrintServiceAttributeSet requestAttributeSet = new HashPrintServiceAttributeSet();
    serviceAttributeSet.add(new PrinterName(printerName, null));
    exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, serviceAttributeSet);
    // ...
    exporter.exportReport();
    
  • Avatar for Marc Nuri
    Marc Nuri
    2007-10-03 11:37
    Hi Paulo,

    First of all, thank you for your response.

    Yes it's true, the search for the printer name is not necessary at all.

    But the code above is very usefull if you use the program across several computers in windows environments.

    Depending on how you install a network printer in windows (there are several ways), if you do it the easy way (double click the printer in a 'My Network Places' computer) you will get a printer with the name "PRINTER NAME in COMPUTERNAME". So your code won't be useful.

    So if you know the exact name of the printer and you know that this name will remain in whatever computer you install your program, then you should Paulo's code. Your program will load faster.
  • Avatar for Roose
    Roose
    2008-02-27 15:47
    <JASPER Multiples clientes via WEB>

    Hello,

    I have a similar problem: in your webservice application we use servlets to build custom report (about 15O subreports/ 50 pages). But if one more cliente click the print button the reports is not generated. Please, someone can help me?

    Best regards

    Roosewelt
  • Avatar for RS
    RS
    2008-04-08 15:39
    How to display dynamically generated jasper report in -> iFrame jsp page - Please Help...
  • Avatar for TChelliah
    TChelliah
    2008-07-24 21:21
    Thank you for sharing this.
  • Avatar for Sammy
    Sammy
    2008-08-12 18:08
    Marc,

    I created a customized label using iReport and if I print it from PDFreader it prints fine. But, if I print it from my java program it prints extra 4 labels. It takes the default paper size as A4. I tried to set PRintImageableAra as shown below with no luck.

    printRequestAttributeSet.add(new javax.print.attribute.standard.MediaPrintableArea(0,0,4,2,javax.print.attribute.standard.MediaPrintableArea.INCH ));

    Can you please help me with this.

    Thanks!
  • Avatar for akbar
    akbar
    2008-09-28 13:45
    how to set paper size in custom ?.for example a half of A4. because the size is not exist in default MediaSizeName. thank
  • Avatar for R. E. Velasquez
    R. E. Velasquez
    2008-10-01 22:25
    Thanks for this very helpful tutorial, keep it up!
  • Avatar for pegah
    pegah
    2008-10-19 07:40
    Hi

    thanks for ur tutorial.it was very helpful for me.

    i want to print three jasper file in one print job task and i dont want printer to stop and start between each report printing. i think this way we can speed up printing multiple reports.

    can u help me please?
  • Avatar for G
    G
    2008-11-11 17:47
    Thanks so much, it was helpful!
  • Avatar for naveen
    naveen
    2008-11-13 21:54
    hi all,

    thanks for the code it was useful for me. but my req. is some what different, it is like my application provides the printer name in string format and jasper report related java code has to take the printer name,input xml,jrxml and has to print at the appropriate printer. so please any one help me out with sample code.
  • Avatar for naveen at port
    naveen at port
    2008-11-13 21:56
    hi all,

    thanks for the code it was useful for me. but my requirement. is some what different, it is like my application provides the printer name in string format and jasper report related java code has to take the printer name,input XML and has to print at the appropriate printer. so please any one help me out with sample code.
  • Avatar for Romina
    Romina
    2009-01-07 16:19
    Marc, buen dia, muy bueno tu articulo de como establecer la impresora en la que se va a imprimir y otros atributos preestablecidos, lo probe y me funciona perfectamente excepto que el reporte que yo imprimo tiene un tamaño personalizado y cuando lo imprimo de esta forma no me imprime correctamente.
    Yo lo habia solucionado generando una impresora con un papel preestablecido y al imprimir con el printer manager funcionaba correctamente. Como hago con esta forma que vos planteas para pasar el tamañp y los margenes de la hoja que tiene que usar la impresora?
  • Avatar for Steve
    Steve
    2009-01-13 21:54
    I have a for loop in my java code that prints 1..n jasper reports. I would like the print dialog to show when I print the first report, but not for reports 2..n. How can I save the print properties from the first report and apply them to all other reports being printed?
  • Avatar for Romina
    Romina
    2009-01-13 22:56
    Hola yo nuevamente, solucione lo que te consultaba anteriormente. Pero tengo un problema un poco extraño. Cuando imprimo la primera vez que ingreso en la app java me imprime con unos margenes que nada que ver con los que tiene el jrxml, pero la segunda, la tercera, etc... vez me lo imprime bien.

    Muchas Gracias

    Saludos
  • Avatar for Susan M
    Susan M
    2009-01-30 17:24
    I've inherited a java web app running on tomcat whose main purpose is to print jasper reports. We are passing the printer information and our successful in selecting the printer similar to what you are doing above.

    However, I now need to modify the code so that it specifies a specific tray on the printer to print the report.
    All the reports are the same size so the media size will not change but I need to be able to specify tray 2, 3, or 4. The use of this application limited to a specific audience so I know they are printing to 1 of 4 printers which are the same exact model. Only the printer name changes between them.

    Thanks,

    Susan
  • Avatar for Cecilia
    Cecilia
    2009-07-30 20:48
    Hola, estoy teniendo un problema con una impresora de etiquetas.
    Si bien le defino el area, tal como definiste mas arriba, me corta la etiqueta hacia la derecha. Como si agregara un margen.

    Pense que era por el area imprimible de la impresora pero desde el Ireport se imprime completamente.

    Este es mi codigo
    JasperPrint jp = JasperFillManager.fillReport(report, parameters, new ReportProvider(data));
    JRPrintServiceExporter exporter = new JRPrintServiceExporter();
    PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
    PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
    if(services[selectedService]!=null) {
      float w= (jp.getPageWidth());
      float h=(jp.getPageHeight());
      MediaSizeName mediaSizeName = MediaSize.findMedia(w,h,MediaPrintableArea.INCH);
      printRequestAttributeSet.add(mediaSizeName);
      int unidad = MediaPrintableArea.MM;
      // Busco el tamano de papel de la impresora más parecido
      printRequestAttributeSet.add(MediaSize.findMedia(w, h, unidad));
      // Configuro el area de impresion
      printRequestAttributeSet.add(new MediaPrintableArea(0, 0, w, h, unidad));
      // Orientacion
      OrientationRequested orientation = OrientationRequested.PORTRAIT;
      if(jp.getOrientation() == JRReport.ORIENTATION_LANDSCAPE) {
        orientation = OrientationRequested.LANDSCAPE;
      }
      printRequestAttributeSet.add(orientation);
      printRequestAttributeSet.add(new Copies(copies));
      exporter.setParameter(JRExporterParameter.JASPER_PRINT, jp);
      exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE, services[selectedService]);
      exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, services[selectedService].getAttributes());
      exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, printRequestAttributeSet);
      exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
      exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.FALSE);
      exporter.exportReport();
    
    Sabrias decirme que puede estar generando ese error? Gracias!

    Cecilia.
  • Avatar for nowhere
    nowhere
    2009-09-25 09:48
    My application needs tray selection. However, I cannot find any method to select different tray in JasperReport. Other than printer tray selection, I would like to see whether there is any method to change the top margin, left margin and right margin. Can anyone give me a quick solution?
  • Avatar for good girl
    good girl
    2009-12-03 05:21
    I created jasper report from windows OS. And my users using linux mandriva as their OS. My program and reports run well in their computer. But when they are trying to print (click the printer button), it appeared nothing. Although when I ran it in windows, the print dialog did show. Can you help me with this problem? Thx before.
  • Avatar for Aerobie Disc
    Aerobie Disc
    2011-07-19 21:05
    Thank you for sharing to us.there are many person searching about that now they will find enough resources by your post.
  • Avatar for kavitha
    kavitha
    2011-08-11 13:04
    Hi,

    Nice code.

    When i try printing a jarper report using this code, it gives me Error java.awt.HeadlessException. Why does this happen.

    It works if i use JasperPrintManager.printReport(jasperPrint, false); and prints the report in default printer.

    I use windows.

    Is there any way of printing the report in client printer?

    Thanks.
  • Avatar for Peanut Butter
    Peanut Butter
    2011-08-18 17:05
    I find this information very useful and it has considerably saved my time. You have shared a nice blog. I really want ot say you thanks for sharing this nice article with us.
  • Avatar for Mikeymike
    Mikeymike
    2011-08-31 04:14
    Now that solves a few problems I was having, thanks!!!
  • Avatar for writing? I have a presentation next week
    writing? I have a presentation next week
    2011-12-10 10:25
    Thank you for another great article. Where else could anyone get that kind of information in such a perfect way of
  • Avatar for David
    David
    2012-01-17 22:00
    tengo un problema a la hora de imprimir una factura, lo que hace es que me sale solo una parte como si el margen o el tamaño de impresion se cortara a 11x13cm utilizando el codigo.
    nose si alguien tiene el mismo problema pero por favor ahi les dejo mi msn si alguien ya lo tiene resuelto
  • Avatar for Security Companies St Davids
    Security Companies St Davids
    2012-03-23 07:59
    Its a wonderful post and also informative. I would like to thank you for sharing this information. Thanks for sharing
  • Avatar for Sabina Cao
    Sabina Cao
    2012-05-24 19:23
    You write some great code. I'm learning but this is far more advanced than I am right now. I hope to be this good someday.
  • Avatar for Shamseer pc
    Shamseer pc
    2013-03-21 10:32
    thanks for the code,when i executed this code,report is getting printed on server side.can you please hel me,how to print on client side..? thanks in advance.
  • Avatar for jerome
    jerome
    2013-06-06 15:41
    Thks a lot, you just forgot the "Break;" to qui the loop in the for loop bellow "selectedService = i;".

    Good continuation
  • Avatar for BENKHAOUA SIDAHMED
    BENKHAOUA SIDAHMED
    2014-05-08 19:23
    hi, i have this proble i use a servlet

    java.awt.HeadlessException
    18:20:40,761 ERROR [stderr] (http-/0.0.0.0:8080-3) at sun.print.RasterPrinterJob.printDialog(RasterPrinterJob.java:795)
    18:20:40,761 ERROR [stderr] (http-/0.0.0.0:8080-3) at net.sf.jasperreports.engine.export.JRPrintServiceExporter.exportReport(JRPrintServiceExporter.java:258)
    18:20:40,762 ERROR [stderr] (http-/0.0.0.0:8080-3) at com.iconsoft.apps.gestioncommercial.web.servlet.PrintBarCode.print(PrintBarCode.java:204)
    18:20:40,762 ERROR [stderr] (http-/0.0.0.0:8080-3) at com.iconsoft.apps.gestioncommercial.web.servlet.PrintBarCode.doGet(PrintBarCode.java:115)
    18:20:40,763 ERROR [stderr] (http-/0.0.0.0:8080-3) at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
    18:20:40,763 ERROR [stderr] (http-/0.0.0.0:8080-3) at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    18:20:40,763 ERROR [stderr] (http-/0.0.0.0:8080-3) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
    18:20:40,764 ERROR [stderr] (http-/0.0.0.0:8080-3) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
    18:20:40,764 ERROR [stderr] (http-/0.0.0.0:8080-3) at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62)
    18:20:40,765 ERROR [stderr] (http-/0.0.0.0:8080-3) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
    18:20:40,765 ERROR [stderr] (http-/0.0.0.0:8080-3) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
    18:20:40,765 ERROR [stderr] (http-/0.0.0.0:8080-3) at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
    18:20:40,766 ERROR [stderr] (http-/0.0.0.0:8080-3) at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
    18:20:40,766 ERROR [stderr] (http-/0.0.0.0:8080-3) at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
    18:20:40,766 ERROR [stderr] (http-/0.0.0.0:8080-3) at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
    18:20:40,766 ERROR [stderr] (http-/0.0.0.0:8080-3) at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
    18:20:40,767 ERROR [stderr] (http-/0.0.0.0:8080-3) at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
    18:20:40,767 ERROR [stderr] (http-/0.0.0.0:8080-3) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
    18:20:40,767 ERROR [stderr] (http-/0.0.0.0:8080-3) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
    18:20:40,768 ERROR [stderr] (http-/0.0.0.0:8080-3) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
    18:20:40,768 ERROR [stderr] (http-/0.0.0.0:8080-3) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
    18:20:40,768 ERROR [stderr] (http-/0.0.0.0:8080-3) at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:161)
    18:20:40,768 ERROR [stderr] (http-/0.0.0.0:8080-3) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java)
    18:20:40,769 ERROR [stderr] (http-/0.0.0.0:8080-3) at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50)
    18:20:40,769 ERROR [stderr] (http-/0.0.0.0:8080-3) at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:165)
    18:20:40,769 ERROR [stderr] (http-/0.0.0.0:8080-3) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
    18:20:40,769 ERROR [stderr] (http-/0.0.0.0:8080-3) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    18:20:40,770 ERROR [stderr] (http-/0.0.0.0:8080-3) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    18:20:40,770 ERROR [stderr] (http-/0.0.0.0:8080-3) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:372)
    18:20:40,770 ERROR [stderr] (http-/0.0.0.0:8080-3) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
    18:20:40,771 ERROR [stderr] (http-/0.0.0.0:8080-3) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:679)
    18:20:40,771 ERROR [stderr] (http-/0.0.0.0:8080-3) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:931)
    18:20:40,771 ERROR [stderr] (http-/0.0.0.0:8080-3) at java.lang.Thread.run(Thread.java:722)
        
  • Avatar for miren
    miren
    2015-06-24 08:38
    Here I was trying to print jasper report via java code silently using jasper API.

    Here is what I have done to print Jasper Report, my code simply calls the JRPrintServiceExporter. exportReport(), provided JasperPrint and PrintServiceAttributeSet object parameters are set to JRPrintServiceExporter object. Also IgnorePagination property is properly set in the JasperPrint object which is getting passed into Jasper engine. Jasper engine prints the report to printer in a single page which is fine. But all the report data are not getting printed which is actual issue here.

    I am using Jasperreport 5.6.0

    Please suggest what should we do to overcome this problem.
  • Avatar for SHAIK RAHAMATHALI
    SHAIK RAHAMATHALI
    2016-07-24 07:14
    Every time i am printing jasper report, it printing on server side configured printer . i need to print jasper report on client side configured printer.
    please help me . thanks
    • Avatar for Marc Nuri
      Marc Nuri
      2016-07-31 11:47
      Hello Shaik
      This tutorial is useful for Swing, JavaFX or any other client-side java application. Probably you are sending print commands to a webapplication thus your prints will come out through a server printer.
      To print through a client side configured printer you should implement an applet, jnlp or some other solution that receives the document to print from the server (pdf, ps, plain text...) and then issues the print command on the client's computer environment.
  • Avatar for esi
    esi
    2018-02-21 07:32
    Hi, can ireport send reports to to thermal (POS) Printer? Which type of Printers can be chosen by ireport?
    Thanks in advance..
    • Avatar for Marc Nuri
      Marc Nuri
      2018-02-22 05:58
      If the printer supports graphics yes.
      Printing a JasperReport into a thermal printer would be the same as printing a PDF.
      I've worked with Zebra and TEC label printers and most of them supported graphics. The main drawback is that this kind of printing is much slower than sending just plain text directly to the printer.
      • Avatar for esi
        esi
        2018-02-23 07:30
        Thank you for your fast response!. I search on the internet how can i sent to thermal printer ireports with java but i couldnt find good information.. Could you recommend any website or documents about this?.. Thanks!

Post navigation
Java App for PostgreSQL scheduled backups using pg_dump (Windows only)JVM for Windows Mobile (J2ME) // PocketPC - PDA MySaifu
© 2007 - 2025 Marc Nuri