Open HTML to PDF is a pure-Java library for rendering arbitrary well-formed XML/XHTML (and even HTML5) using CSS 2.1 for layout and formatting, outputting to PDF or images.
Use this library to generated nice looking PDF documents. But be aware that you can not throw modern HTML5+ at this engine and expect a great result. You must special craft the HTML document for this library and use it's extended CSS feature like #31 or #32 to get good results. Avoid floats near page breaks and use table layouts.
- Showcase Document - PDF
- Integration guide - get maven artifacts and code to get started.
- Documentation wiki
- Template Author Guide - PDF - DEPRECATED - Prefer wiki - Moving info to wiki
- RC16 Online Sandbox - Please do not abuse.
- Sample Project - Pretty Resume Generator
Open HTML to PDF is distributed under the LGPL. Open HTML to PDF itself is licensed under the GNU Lesser General Public License, version 2.1 or later, available at http://www.gnu.org/copyleft/lesser.html. You can use Open HTML to PDF in any way and for any purpose you want as long as you respect the terms of the license. A copy of the LGPL license is included as license-lgpl-2.1.txt or license-lgpl-3.txt in our distributions and in our source tree.
Open HTML to PDF uses a couple of FOSS packages to get the job done. A list of these, along with the license they each have, is listed in the LICENSE file in our distribution.
Open HTML to PDF is based on Flying-saucer. Credit goes to the contributors of that project. Code will also be used from neoFlyingSaucer
- OPEN HTML TO PDF is tested with OpenJDK 8 and 11, Oracle JDK 8 and 11. As of RC18, it requires at least Java 8 to run.
- No, you can not use it on Android.
- You should be able to use it on Google App Engine (Java 8 or greater environment). Let us know your experience.
Flowing columns are not implemented.Implemented in RC12.- No, it's not a web browser.
Test cases, failing or working are welcome, please place them
in /openhtmltopdf-examples/src/main/resources/testcases/
and run them
from /openhtmltopdf-examples/src/main/java/com/openhtmltopdf/testcases/TestcaseRunner.java
.
- #284 #288 IMPORTANT: This release was brought forward due to a CVE in Apache Batik used by the optional SVG module. While this project strongly advises not to use untrusted XML either in SVG or XHTML, you may be using Batik in another part of your project and therefore it is a good idea to update. Thanks a lot @ghenadiibatalski, @chubbard
- #286 #281 Fix for text decorations/background incorrect coverage in justified text. Thanks @koritakoa, @allartammik
- #280 This will be the last release compatible with Java 7, from now on Java 8 or above will be required. Thanks for everyone's thoughts on this.
- #279 #264 IMPORTANT: This release was brought forward so that we link against PDFBOX-2.0.12 as previous versions had another DOS security vulnerability when parsing arbitary PDF files. Also there was a security issue in the old version of JSoup used by the optional jsoup-dom-converter module. While I believe these vulnerabilities should not impact this project directly, having an insecure library on your classpath may be dangerous if you use it for other tasks. Thanks @rototor, @dheid
- #279 Support for testing and running on JDK-11. Extensive work by @rototor. Thanks.
- #278 Support for additional PDF/A conformance levels. Thanks @TheUnnamedDude
- 87dc1a9 Fixed nasty bug where positioned elements (absolute, fixed) were being printed twice. By @danfickle
- #271 Support right-to-left list items. Thanks @ieugen for work, @sandre1 for reporting.
- Much more work on the fast renderer. But not ready for prime time yet!
- NOTE: Started moving project documentation to wiki.
- #228 Support for letter-spacing CSS property. By @danfickle
- #143 Merging of remaining items thanks to @backslash47
- Support for
box-sizing:border-box
. With additional work (for min/max width/height) by @danfickle - Text justification for embedded unicode fonts
- #250 Optional PDF/A conformance. Thanks @syjer
- Support for
- #252 Incorrect placement of form controls. Thanks @tiredelk
- #249 Cache font metrics across runs to avoid having to load fallback fonts on each run. By @danfickle
- #254 Allow use of SVG image in image tag. Thanks @syjer
- IMPORTANT: This release was brought forward so that we link against PDFBOX-2.0.11 as previous versions had a security vulnerability when parsing arbitary PDF files. While I believe this should not impact this project directly, having an insecure library on your classpath may be dangerous if you use it for other tasks. #241 #239 Thanks @rototor, @cseblog
- NOTE: This release incorportate a new faster renderer (especially for large documents) that is in alpha state. Specifically, it can be used with everything except inline-blocks.
You can start testing it now with
builder.useFastMode()
#180 Thanks @rajaningle @javimartinez @dilworks @rototor - Image with CSS max-width and max-height incorrectly scaled #242 Thanks @koan00
- Bold and italic emulation #240 Thanks @syjer @backslash47
- Work on correctly outputting multiple HTML files to one PDF #222 Thanks @rototor
- ONGOING: Attempt at fixing font file handle leak #215 Thanks @rototor
- Don't throw NPE when no base URI is provided #206
- Fix link annotation placement in margin or generated boxes Thanks @jesselong, @Kuhlware, @markhowardnz
- Use common base class for PDF and Java2D builder - SOME IMPORTS MAY CHANGE Thanks @rototor
- Major work on transforms, we're getting there, but still test well before use. Thanks @rototor
- Make it possible to set a PDF producer Thanks @schmitch
- Support for JFreeCharts diagrams with simple markup Thanks @rototor
- Ability to stamp another PDF on page Thanks @rototor
- Support for Latex Thanks @rototor
- Support for MathML Thanks @m-a-t
- Support for HTML and MathML character entities such as nbsp, etc
- Allow user to construct their own PDDocument so memory options can be specified Thanks @rajaningle, @javimartinez
- Fixed silly bug and got dramatic performance improvement for large documents
- Fix for XML loading problems where older version of xerces was being picked up Thanks @sosnut
- Fix for XML loading problems with JBoss,Wildfly Thanks @estevandiedrich, @alanhay
- Support image maps on img, object and svg Uses a kong polygon tesselation implementation by sunshine2k
- API BREAKING CHANGE: Support custom shape <=> link maps in object drawers
Note: Shaped links only work in Acrobat Reader. All other PDF reader seem to ignore them.
- Upgrade the PDFBox to 2.0.8 and PDFBox-Graphics2D to 0.10 versions again Thanks @rototor
- Fix incorrect strikethrough offset Thanks @alebar, @backslash47, @izhenka
- Allow percentages for max-width and max-height of images Thanks @backslash47
- Better sizing system for inline SVG images Thanks @harbulot
- Allow uri resolver to resolve uri before checking if a data uri Thanks @AlbanSeurat
- Ability to run examples from maven Thanks @jartysiewicz
- Fix to allow jar scheme urls Thanks @geesen
- Font mapping in custom object drawer rather than using vector shapes Thanks @rototor
- Upgraded PDFBOX to 2.0.7, ICU4J to 59.1 and PDFBOX-GRAPHICS2D to 0.7 Thanks @rototor
- Implemented CSS3 flowing text columns Thanks @miminno
- FIX: Don't write miter values of zero into the PDF, fixes dotted/dashed lines in Acrobat Reader
- Allow collapsed borders with table pagination Thanks @Epimetheus89
- FIX: Dispose of thread local when renderer is cleaned up Thanks @rototor
- FIX: Link handling when identical link positions on multiple pages Thanks @rototor
- FIX: Allow user to disable logging Thanks @GrammyTraore
- Handle TrueType font collections added in builder Thanks @rototor
- Implement custom object drawer for Java2D output Thanks @rototor
- Upgrade PDFBox library to 2.05 Thanks @rototor, PDFBox team
- Support for inline SVG images Thanks @rototor
- Support for outputting paged or continuous images Thanks @rototor
- Don't output acroform for formless document Thanks @aleksandr-m
- Upgraded to PDFBox 2.0.4 Thanks PDFBox team
- Fixed memory leak - properly - in image processing on some JREs Thanks @skjardenCode and @MartyMcMartface
- Initial support for CSS transform property Thanks @rototor
- Add support for max-width and max-height on img elements Thanks @achuinard
- SECURITY ISSUE: Prevent XXE Attacks Thanks @lillesand
- BREAKING CHANGE: Support for dir attribute and bdi element
- Do not download fonts that are not actually used
- Fixed resolution of relative URLs in inline style declarations
- Added support for hidden controls and submit controls with values
- Corrected naming scheme for form controls Thanks @scoldwell
- Reimplemented text justification Thanks @hiddendog
- Fixed bug in table borders Thanks @rototor
- Added support for -fs-page-break-min-height CSS property Thanks @rototor
- Added support for -fs-table-paginate-repeated-visible CSS property Thanks @rototor
- BREAKING CHANGE: Removed font subset method in builder, replaced with property in font face rule. Example:
-fs-font-subset: complete-font;
- Added support for text, password, textarea, submit, reset, checkbox, radio and select - multiple and single - controls
- BREAKING CHANGE: Changed bi-directional method names in builder to be more consistent.
- Add method to builder to specify custom text transformers
- Add method to builder to specify a custom line breaker Thanks @Magotchi
- Add method to builder to specify replacement text if no specified font can render a character.
- BREAKING CHANGE: Reworked URI resolver, changed FSUriResolver interface and made sure it is used everywhere - See example in integration guide.
- Fixed issue where different size pages in the same document were not being recognized.
- Add method to builder to specify default page size. Example:
builder.useDefaultPageSize(PdfRendererBuilder.PAGE_SIZE_LETTER_WIDTH, PdfRendererBuilder.PAGE_SIZE_LETTER_HEIGHT, PdfRendererBuilder.PAGE_SIZE_LETTER_UNITS);
- BREAKING CHANGE: If no page size is specified in builder or CSS use A4, rather than locale dependent. See above.
- Silently discard control characters, etc at the rendering stage Thanks @scoldwell
- Fixed incorrect spacing when characters are replaced Thanks @scoldwell
- Experimental and unstable SVG support - early prototype
- Replaced non-breaking spaces - and other unusual spaces - with normal space if font does not support them Thanks @rototor
- Added a method for adding a PDF font using an input stream Thanks @aleksandr-m
- Added support for plugging in an external URI resolver
- Added support for plugging in an external cache
- Added support for font fallback for Java2D Thanks @willamette
- Fixed crash issue when document contained CDATA sections Thanks @hiddendog
- Added support for font fallback for PDFs
- Added fluent builder style API for PDF conversion
- Added ability to plugin external HTTP/HTTPS implementation
- Added Jsoup HTML5 to DOM converter module
- Fixed divide-by-zero error in BorderPainter class. Thanks @fenrhil
- Added slf4j logging facade adapter
- Added right-to-left(RTL) and bi-directional text support
- Added output device using PDF-BOX 2.0.0
- Make sure XML Document Builder doesn't resolve external DTDs
- Removed obsolete ITEXT based output devices
- Removed SWT support
- Regressions (please open issue if required):
PDF form controls.Reimplemented in RC5- PDF font types other than built-in and truetype.
- XMP PDF metadata in PDFs.
PDF encryption.Reimplemented in RC5PDF text justificationReimplemented in RC5