i need to transform the output of jsp program into pdf file. suggest me some jar file and code to generate the pdf file of jsp output. iam also retrieving some values from database(mysql). I have read about jasper but it couldn't help me in any way. please help me.
问题:
回答1:
FlyingSaucer/XHTMLRenderer (https://github.com/flyingsaucerproject/flyingsaucer) does a good job of HTML > PDF conversion however it does not work by magic: there are a few steps involved.
Assuming you wanted to export an existing JSP via some Link or Button:
PDF export Button calls a some Controller or Servlet passing all params necessary to regenerate the JSP (i.e. as it was originally rendered).
This Action or Servlet has to invoke the JSP (ensuring any required
model attributes are set) and write the Response to a String (rather than writing to the standard response).Pass this String to XHTMLRenderer to generate the PDF.
Stream the btye [] returned by HTMLRenderer to the client.
I have added a complete end-to-end example here using a simple Servlet. However the principles will be the same with any framework so you should be able to adapt as required.
https://github.com/alanhay/jsp-to-pdf-exporter