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>