Java: How can I generate a PDF file from a JSP JSP page?

I need to create a PDF file from a JSP JSP page. I searched the network, but I did not find examples of how to do this. I need to convert the whole page, or maybe just the diagrams that I have on this page.

PS I also use IceFaces.

+7
java pdf jsf icefaces
source share
4 answers

The easiest way is to capture the HTML using Filter and convert it to PDF using the appropriate API, then return the application/pdf data from Filter . It may be possible to support partial submission of IceFaces files to support a subset of the component's output, but you may have to examine the details of IceFaces HTTP requests to figure out how to use this.

+7
source share

As far as I know, this is not possible. You can use Jasper Reports to create a pdf file on the server side. Or you can use PrintPDF , which is a firefox plugin to create one from a web browser.

+2
source share

You may need the following:

  • Capturing (X) the HTML output of your page. This can be done using the following code in your servlet:

     InputStream is = new URL("http://localhost/foo/page.jsf").openStream(); 
  • Convert captured content to pdf. See the rendering of the Flying Saucer (and additionally this stream )

  • "Submit" generated PDF file. That is, just write (print) your pdf file to response.getOutputStream() and set the Content-Type header to response.setContentType("application/pdf")

+2
source share

This may be the answer. Read this article: Combine JSF Front Ends and XHTML Flying Saucer Rendering

+1
source share

All Articles