how to get jsp output in pdf form using coding

不打扰是莪最后的温柔 提交于 2019-11-28 12:23:41

问题


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



来源:https://stackoverflow.com/questions/27617616/how-to-get-jsp-output-in-pdf-form-using-coding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!