Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Name

PDF Stream Plugin

Publisher

Aleksandr Mashchenko

License

Open Source (ASL2)

Version

1.23.20

Homepage

https://github.com/aleksandr-m/struts2-pdfstream

...

A Struts2

Excerpt

 plugin for creating PDF-s from HTML-s, JSP-s, FreeMarker templates and Apache Tiles definitions.

 

The PDF Stream plugin allows to transform a view into a PDF stream and return it as a result from Action.

Default supported views:

  • HTML
  • JSP
  • FreeMarker template
  • Apache Tiles 2.x definition
  • Apache Tiles 3.x definition

Features Overview

  • Direct transformation of HTML, JSP-s, FreeMarker templates template and Apache Tiles definitions definition to PDF via Struts2 result
  • PDF content styling using CSS
  • Support of wide range of characters in PDF thanks to the DejaVu fonts
  • Can process even Handling of the malformed HTML thanks to the jsoupthe jsoup

Showcase

Showcase application can be downloaded from the Maven Central Repository.

Download struts2-pdfstream-showcase

Contributing

Found a bug or have a feature request? Create a new issue or submit a Pull Request.

...

Code Block
<dependencies> 
    ...
    <dependency> 
        <groupId>com.amashchenko.struts2.pdfstream</groupId>
        <artifactId>struts2-pdfstream-plugin</artifactId>
        <version>1.23.2<0</version> 
    </dependency> 
    ...
</dependencies> 

 

If you intend to transform Apache Tiles definition additional jar must be included.

For the Apache Tiles 2.x support add the struts2-pdfstream-tiles.

Code Block
<dependency>
    <groupId>com.amashchenko.struts2.pdfstream</groupId>
    <artifactId>struts2-pdfstream-tiles</artifactId>
    <version>1.23.2<0</version>
</dependency> 

 

For the Apache Tiles 3.x support add the struts2-pdfstream-tiles3.

Code Block
<dependency>
    <groupId>com.amashchenko.struts2.pdfstream</groupId>
    <artifactId>struts2-pdfstream-tiles3</artifactId>
    <version>1.23.2<0</version>
</dependency> 

Usage

...

Code Block
<action name="jspToPdf">
    <result type="pdfstream">
        <param name="location">/WEB-INF/pages/tableexample.jsp</param>
        <param name="cssPaths">css/bootstrap.min.css, css/style.css</param>
        <param name="contentDisposition">attachment;filename=jsppdf.pdf</param>
    </result>
</action>

...

HTML to PDF stream

Code Block
<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>

Tiles definition to PDF stream

Code Block
<action name="tilesToPdf">
    <result type="pdfstream">
        <param name="location">table<>example</param>
        <param name="renderer">tiles</param>
        <param name="contentDisposition">attachment;filename=tilespdf.pdf</param>
    </result>
</action>

...

FreeMarker template to PDF stream

Code Block
<action name="freemarkerToPdf">
    <result type="pdfstream">
        <param name="location">/WEB-INF/ftl/tableexample.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>

Extending the plugin

Adding support for other views

This plugin can be easily extended in order to add support for transforming other views (e.g. Velocity) into PDF.

  1. Implement com.amashchenko.struts2.pdfstream.ViewRenderer interface.
  2. Create bean definition in struts.xml or in struts-plugin.xml with type="com.amashchenko.struts2.pdfstream.ViewRenderer" and custom name.

    Code Block
    <bean type="com.amashchenko.struts2.pdfstream.ViewRenderer" class="some.package.CustomRenderer" name="customrenderer" /> 
  3. Use pdfstream result with the renderer parameter set to the name of the bean you have defined.

    Code Block
    <action name="customToPdf">
        <result type="pdfstream"> 
            <param name="location">example</param> 
            <param name="renderer">customrenderer</param>
        </result>
     </action>