https://github.com/aleksandr-m/struts2-pdfstream
A Struts2 plugin for creating PDF-s from HTML-s, JSP-s, FreeMarker templates and Apache Tiles definitions.
https://github.com/aleksandr-m/struts2-pdfstream
apache-tiles freemarker jsp openhtmltopdf pdf pdfbox struts2 struts2-plugin
Last synced: 6 months ago
JSON representation
A Struts2 plugin for creating PDF-s from HTML-s, JSP-s, FreeMarker templates and Apache Tiles definitions.
- Host: GitHub
- URL: https://github.com/aleksandr-m/struts2-pdfstream
- Owner: aleksandr-m
- License: apache-2.0
- Created: 2014-12-27T21:06:21.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2023-06-14T20:22:55.000Z (over 2 years ago)
- Last Synced: 2024-05-01T12:36:51.300Z (over 1 year ago)
- Topics: apache-tiles, freemarker, jsp, openhtmltopdf, pdf, pdfbox, struts2, struts2-plugin
- Language: Java
- Homepage:
- Size: 494 KB
- Stars: 12
- Watchers: 4
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Struts2 PDF Stream Plugin
[](https://maven-badges.herokuapp.com/maven-central/com.amashchenko.struts2.pdfstream/struts2-pdfstream-plugin/)
[](https://www.apache.org/licenses/LICENSE-2.0.html)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 definition## Struts2 PDF Stream v2
#### Apache PDFBox 2
Starting from 2.0.0, HTML into PDF rendering is done by the [openhtmltopdf](https://github.com/danfickle/openhtmltopdf) library which uses the [Apache PDFBox 2](https://pdfbox.apache.org/) to create PDF documents.
Apache PDFBox 2 is an open source Java tool for working with PDF documents and it is published under the Apache License v2.0.#### Apache Struts 2.5
Upgraded to be compatible with Apache Struts 2.5
#### Java 7
Switched to Java 7
## Features Overview
- Direct transformation of HTML, JSP, FreeMarker template and Apache Tiles definition to PDF via Struts2 result
- PDF content styling using CSS
- Support of wide range of characters in PDF thanks to the [DejaVu fonts](https://dejavu-fonts.github.io/)
- Handling of the malformed HTML thanks to the [jsoup](https://jsoup.org/)## Showcase
Showcase application can be downloaded from the Maven Central Repository.
[Download struts2-pdfstream-showcase](https://search.maven.org/remotecontent?filepath=com/amashchenko/struts2/pdfstream/struts2-pdfstream-showcase/2.0.0/struts2-pdfstream-showcase-2.0.0.war)
## Contributing
Found a bug or have a feature request? [Create a new issue](https://github.com/aleksandr-m/struts2-pdfstream/issues/new) or submit a [Pull Request](https://github.com/aleksandr-m/struts2-pdfstream/pulls).
## Questions
If you have questions about how to use `struts2-pdfstream-plugin` [create a new issue](https://github.com/aleksandr-m/struts2-pdfstream/issues/new) or ask a question on [Stack Overflow](https://stackoverflow.com/questions/tagged/struts2-pdfstream-plugin).
## Installation
Copy following jars into your classpath (WEB-INF/lib):
- struts2-pdfstream-plugin-2.0.0.jar
- jsoup-1.9.2.jar
- openhtmltopdf-core-0.0.1-RC4.jar
- openhtmltopdf-pdfbox-0.0.1-RC4.jar
- pdfbox-2.0.0.jar
- fontbox-2.0.0.jarIf you are using Maven, add this to your project POM:
...
com.amashchenko.struts2.pdfstream
struts2-pdfstream-plugin
2.0.0
...
If you intend to transform Apache Tiles definition additional jar must be included.
For the Apache Tiles support add the `struts2-pdfstream-tiles`.
com.amashchenko.struts2.pdfstream
struts2-pdfstream-tiles
2.0.0
## Usage
1. Install this plugin by adding dependency to your POM or by copying jars into /WEB-INF/lib directory.
2. Make your action package extend `pdfstream-default` package or add `pdfstream` result type.
3. Use `pdfstream` result type.## Examples
### JSP to PDF stream
/WEB-INF/pages/example.jsp
css/bootstrap.min.css, css/style.css
attachment;filename=jsppdf.pdf
### HTML to PDF stream
/WEB-INF/pages/example.html
css/bootstrap.min.css, css/style.css
attachment;filename=htmlpdf.pdf
### Tiles definition to PDF stream
example
tiles
attachment;filename=tilespdf.pdf
### FreeMarker template to PDF stream
/WEB-INF/ftl/example.ftl
freemarker
css/bootstrap.min.css, css/style.css
attachment;filename=ftlpdf.pdf
## Extending the plugin
### Adding support for other viewsThis 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.
3. Use `pdfstream` result with the `renderer` parameter set to the name of the bean you have defined.
example
customrenderer