Client side JasperReports printing?

I developed a web application that uses JasperReports. I noticed that reports print to the server side.

How to force reports to print on the client side (from a web browser)?

Any ideas would be helpful.

+2
source share
1 answer

Assuming you have a server architecture:

  • Get the HttpServletResponse instance handle with HttpServletResponse response = this.getThreadLocalResponse(); (eg).
  • Set various headers to indicate attachment of the file.
      HttpServletResponse response = getServletResponse ();
     response.setHeader ("Content-Description", "File Transfer");
     response.setHeader ("Content-Disposition", "attachment; filename =" +
       "report.pdf");
     response.setHeader ("Content-Type", "application / pdf");
     response.setHeader ("Content-Transfer-Encoding", "binary");
    
  • Configure JRExporter (jre) to use the HttpServletRespone output stream:
      jre.setParameter( JRExporterParameter.OUTPUT_STREAM, getOutputStream() ); 
  • Run the report.

The browser will prompt the user to save the report as a PDF file. User can print PDF.

+1
source

Source: https://habr.com/ru/post/1310814/


All Articles