Home
Analytics
How to send the PDF response from a servlet to the client ?
sgeovar
I use servlet to create a PDF report. I'm able to access it in the browser. Is it possible to access the pdf from any other client tool ? For ex : the client will send the http request to the servlet. If it is a browser it is ok. How to send the PDF response to some other clients ?? Code ends with task.run(); How to return the response from the servlet to the client so that PDF report can be shown on the client ?
Thanks
Find more posts tagged with
Comments
johnw
Assuming your have an OutputStream (HttpOutputStream, or HttpServletResponse.getOutputStream), you would do something like:
RenderOption renderOption = new RenderOption();
renderOption.setOutputStream(httpServletResponse.getOutputStream());
renderOption.setOutputFormat("pdf");
task.setRenderOption(renderOption);
task.run();
task.close();
You may need to flush the outputstream as well. I haven't needed to work with servlets in this way in a while, so my memory is a little fuzzy.
John
sgeovar
Thanks John.