如何使用编码获得pdf形式的jsp输出 [英] how to get jsp output in pdf form using coding

查看:133
本文介绍了如何使用编码获得pdf形式的jsp输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将jsp程序的输出转换为pdf文件。建议我一些jar文件和代码生成pdf文件的jsp输出。 iam还从数据库(mysql)检索一些值。
我读过关于jasper,但它不能帮助我在任何方式。请帮帮我。

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.

推荐答案

FlyingSaucer / XHTMLRenderer( https://github.com/flyingsaucerproject/flyingsaucer )做一个很好的HTML> PDF转换,但它不工作的魔法:涉及到几个步骤。

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.

假设您想通过一些链接或按钮导出现有的JSP:

Assuming you wanted to export an existing JSP via some Link or Button:


  • 一些控制器或Servlet通过重新生成JSP所需的所有
    params(即原来是
    呈现)。

  • PDF export Button calls a some Controller or Servlet passing all params necessary to regenerate the JSP (i.e. as it was originally rendered).

或Servlet必须调用JSP(确保设置任何所需的

模型属性),并将响应写入字符串(而不是写入标准响应的
)。

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).

将此String传递给XHTMLRenderer以生成PDF。

Pass this String to XHTMLRenderer to generate the PDF.

将HTMLRenderer返回的btye [

Stream the btye [] returned by HTMLRenderer to the client.

我在这里使用一个简单的Servlet添加了一个完整的端到端示例。但是,任何框架的原则都是一样的,所以你应该能够根据需要进行调整。

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

这篇关于如何使用编码获得pdf形式的jsp输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆