struts2 pdfstream
1.0.0
PDF流插件允许将视图转换为PDF流,并将其归因于操作。
默认支持的视图:
从2.0.0开始,HTML进入PDF渲染,由OpenHTMLTOPDF库完成,该库使用Apache PDFBox 2创建PDF文档。 Apache PDFBox 2是用于使用PDF文档的开源Java工具,并在Apache许可证v2.0下发布。
升级到与Apache Strut 2.5兼容
切换到Java 7
可以从Maven Central存储库下载展示应用程序。
下载Struts2-PDFStream-Showcase
找到错误还是有功能请求?创建新问题或提交拉动请求。
如果您对如何使用struts2-pdfstream-plugin有疑问,请创建一个新问题或在堆栈溢出上提出问题。
将JARS跟随JARS复制到您的classPath(Web-Inf/lib):
如果您使用的是Maven,请将其添加到您的项目pom:
<dependencies>
...
<dependency>
<groupId>com.amashchenko.struts2.pdfstream</groupId>
<artifactId>struts2-pdfstream-plugin</artifactId>
<version>2.0.0</version>
</dependency>
...
</dependencies>
如果您打算转换Apache图块,则必须包括其他JAR。
对于Apache图块,支持添加struts2-pdfstream-tiles 。
<dependency>
<groupId>com.amashchenko.struts2.pdfstream</groupId>
<artifactId>struts2-pdfstream-tiles</artifactId>
<version>2.0.0</version>
</dependency>
pdfstream-default软件包或添加pdfstream结果类型。pdfstream结果类型。 <action name="jspToPdf">
<result type="pdfstream">
<param name="location">/WEB-INF/pages/example.jsp</param>
<param name="cssPaths">css/bootstrap.min.css, css/style.css</param>
<param name="contentDisposition">attachment;filename=jsppdf.pdf</param>
</result>
</action>
<action name="htmlToPdf">
<result type="pdfstream">
<param name="location">/WEB-INF/pages/example.html</param>
<param name="cssPaths">css/bootstrap.min.css, css/style.css</param>
<param name="contentDisposition">attachment;filename=htmlpdf.pdf</param>
</result>
</action>
<action name="tilesToPdf">
<result type="pdfstream">
<param name="location">example</param>
<param name="renderer">tiles</param>
<param name="contentDisposition">attachment;filename=tilespdf.pdf</param>
</result>
</action>
<action name="freemarkerToPdf">
<result type="pdfstream">
<param name="location">/WEB-INF/ftl/example.ftl</param>
<param name="renderer">freemarker</param>
<param name="cssPaths">css/bootstrap.min.css, css/style.css</param>
<param name="contentDisposition">attachment;filename=ftlpdf.pdf</param>
</result>
</action>
可以轻松扩展此插件,以增加对将其他视图(例如速度)转换为PDF的支持。
实现com.amashchenko.struts2.pdfstream.ViewRenderer接口。
在struts.xml或struts-plugin.xml中创建bean定义,并使用type="com.amashchenko.struts2.pdfstream.ViewRenderer"和custom Nuber创建bean定义。
<bean type="com.amashchenko.struts2.pdfstream.ViewRenderer"
class="some.package.CustomRenderer" name="customrenderer" />
将pdfstream结果与renderer参数设置为您定义的bean的名称。
<action name="customToPdf">
<result type="pdfstream">
<param name="location">example</param>
<param name="renderer">customrenderer</param>
</result>
</action>