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.
source share