Openhtmltopdf
An HTML to PDF library for the JVM. Based on Flying Saucer and Apache PDF-BOX 2. With SVG image support. Now also with accessible PDF support (WCAG, Section 508, PDF/UA)!
Install / Use
/learn @danfickle/OpenhtmltopdfREADME
OPEN HTML TO PDF

OVERVIEW
Open HTML to PDF is a pure-Java library for rendering a reasonable subset of well-formed XML/XHTML (and even some HTML5) using CSS 2.1 (and later standards) 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.
GETTING STARTED
- Integration guide - get maven artifacts and code to get started.
- 1.0.10 Online Sandbox - Now with logs!
- Templates for Openhtmltopdf - MIT licensed templates that work with this project. Updated 2021-09-21.
- Showcase Document - PDF
- Documentation wiki
- Template Author Guide - PDF - DEPRECATED - Prefer wiki - Moving info to wiki
- Sample Project - Pretty Resume Generator
DIFFERENCES WITH FLYING SAUCER
- Uses the well-maintained and open-source (LGPL compatible) PDFBOX as PDF library, rather than iText.
- Proper support for generating accessible PDFs (Section 508, PDF/UA, WCAG 2.0).
- Proper support for generating PDF/A standards compliant PDFs.
- New, faster renderer means this project can be several times faster for very large documents.
- Better support for CSS3 transforms.
- Automatic visual regression testing of PDFs, with many end-to-end tests.
- Ability to insert pages for cut-off content.
- Built-in plugins for SVG and MathML.
- Font fallback support.
- Limited support for RTL and bi-directional documents.
- On the negative side, no support for OpenType fonts.
- Footnote support.
- Much more. See changelog below.
LICENSE
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.
An exception to this is the pdf-a testing module, which is licensed under the GPL. This module is not distributed to Maven Central and is for testing only.
Open HTML to PDF uses a couple of FOSS packages to get the job done. A list of these can be found in the dependency graph.
CREDITS
Open HTML to PDF is based on Flying-saucer. Credit goes to the contributors of that project. Code will also be used from neoFlyingSaucer
FAQ
- OPEN HTML TO PDF is tested with OpenJDK 8, 11 and 17 (early access). 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.
- <s>Flowing columns are not implemented.</s> Implemented in RC12.
- No, it's not a web browser. Specifically, it does not run javascript or implement many modern standards such as flex and grid layout.
TEST CASES
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.
CHANGELOG
head - 1.0.11-SNAPSHOT
- See commit log.
1.0.10 (2021-September-13)
NOTE: After this release the old slow renderer will be deleted. Fast mode has been the default (since 1.0.5) so you only have to check your code if you are calling the useSlowMode method which will be removed.
- #551 SECURITY Fix near-infinite loop for very deeply nested content with
page-break-inside: avoidconstraint. Thanks for persisting @swillis12 and debugging @syjer. - #729 SECURITY Upgrade xmlgraphics-commons (used in SVG rendering) to avoid CVE. Thanks @electrofLy.
- #711 Footnote support (beta). See footnote documentation on wiki. Thanks for requesting @a-leithner and @slumki.
- #761 CSS property to disable bevels on borders to prevent ugly anti-aliasing effects, especially on table cells. See -fs-border-rendering property on wiki. Thanks for providing sample @gandboy91.
- #103 Output exception class name and message by default for log messages with an associated exception.
- #711 (mixed) Better boxing for
::beforeand::aftercontent. Should now be able to define a border around pseudo content correctly. - #738 Support for additional elements in PDF/UA including art, part, sect, section, caption and blockquote. Thanks @AndreasJacobsen.
- #736 New example of using a dom mutator to implement unsupported content such as font tag attributes. Thanks for requesting @mgabhishek06kodur.
- #707 Fix regression where PDF/UA documents that weren't also PDF/A compliant were missing Dublin Core metadata. Thanks @mgm-rwagner, @syjer.
- #732 Allow
tableelement to be positioned. Thanks @fcorneli. - #727 Allow the use of an initial page number for
pageandpagescounters. Thanks for PR @fanthos.
1.0.9 (2021-June-18)
SECURITY RELEASE: This release was brought forward due to security releases of the PDFBOX and Batik dependencies.
- #722 Upgrade PDFBOX (to 2.0.24) - avoids CVEs in earlier versions and PDFBoxGraphics2D. Thanks a lot @rototor.
- #678 Upgrade Batik Version to 1.14 (CVE-2020-11987) - Again it is strongly advised to avoid untrusted SVG and XML. Thanks @rototor.
- #716 Replace rogue
printlncalls with log calls. Thanks @syjer for PR, @tfo for reporting. - #708 Allow
shape-renderingSVG CSS property. Thanks @syjer for PR, @RAlfoeldi for reporting. - #703 Remove calls to deprecated method calls in JRE standard library. May change XML reader class. Implemented by @danfickle.
- #702 Set timeouts for default HTTP/HTTPS handlers. Thanks for reporting @gengzi.
- 162228 Put links to raster images in SVGs through the URL resolver.
- #694 Fix incorrect B3 paper size. Thanks @lfintalan for reporting with line number!
- ab48fd Do not log a missing font more than once.
NOTE: PDFBOX CVEs relate to the loading of untrusted PDFs in PDFBOX and thus this project is not directly affected. However, it is not a good idea to have CVEs on your classpath.
1.0.8 (2021-March-22)
SECURITY RELEASE
- #675 Update PDFBOX to 2.0.23 to avoid CVEs. Thanks for reporting @Samuel3.
NOTE: These CVEs relate to the loading of untrusted PDFs in PDFBOX and thus this project is not directly affected. However, it is not a good idea to have CVEs on your classpath.
1.0.7 (2021-March-19)
- #650 Support for multiple background images on the one element. Thanks for requesting @baedorf.
- #669 Support fallback fonts. Thanks for requesting @asu2 and assisting @draco1023.
- #640 Implement file embeds via the download attribute on links. Thanks for original PR @syjer and for requesting @lindamarieb and @vader.
- #666 API to get the bottom-most y position of rendered content to be able to position follow on content with other tools. Thanks for extensive reviewing of PR @stechio and for request by @DSW-AK.
- #664 Improved support for PDF/A and PDF/UA standards. Thanks for PR @qligier.
- #653 Fix for inline-block elements with a z-index or transform were being output twice. Thanks for reporting @hannes123bsi.
- #655 Co
