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)!
See the code
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.
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.
Open HTML to PDF is based on Flying-saucer. Credit goes to the contributors of that project. Code will also be used from neoFlyingSaucer
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.
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.
page-break-inside: avoid constraint. Thanks for persisting @swillis12 and debugging @syjer.::before and ::after content. Should now be able to define a border around pseudo content correctly.table element to be positioned. Thanks @fcorneli.page and pages counters. Thanks for PR @fanthos.SECURITY RELEASE: This release was brought forward due to security releases of the PDFBOX and Batik dependencies.
println calls with log calls. Thanks @syjer for PR, @tfo for reporting.shape-rendering SVG CSS property. Thanks @syjer for PR, @RAlfoeldi for reporting.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.
SECURITY RELEASE
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.
target-text function for content property. Thanks for PR @BenjaminVega.IMPORTANT: #615 This is a bug fix release for an endless loop issue when using break-word with floating elements with a top/bottom margin.
SECURITY: #609 Updates Apache Batik SVG renderer to latest version to avoid security issue. If you are using this project to render untrusted SVGs (advised against), you should update immediately. Thanks a lot @halvorbmundal.
IMPORTANT: The fast renderer is now the default in preparation of removing the old slow renderer. To temporarily use the slow renderer, you can call the deprecated method builder.useSlowMode() (PDF output only).
IMPORTANT: #543 This version stays on PDFBOX version 2.0.20 due to a bug with non-breaking spaces in version 2.0.21. Please make sure version 2.0.21 is not on your classpath. This bug has been fixed in the upcoming 2.0.22.
baseUri arg to baseDocumentUri and improve javadoc to avoid confusion. Thanks for reporting @NehalDamania.word-wrap: break-word. Thanks for reporting, testing and investigating @swarl. Thanks for tests and debugging @rototor and @syjer.word-wrap: break-word. If you are using this feature, please upgrade promptly.word-wrap: break-word and soft hyphens. Thanks @rototor for PR, @syjer for analysis and @swarl for reporting.word-wrap: break-word and zero width boxes. Thanks @syjer for analysis and @AlexisCothenet for reporting.mailto: links or any other valid link. Thanks @syjer for PR and @mndzielski for reporting.direction CSS property. Thanks @AnanasPizza for reporting.IOException. Thanks for PR @leonorader.rem CSS unit. Thanks to @leonorader for reporting.content property. Thanks for requesting @Kuhlware.builder.useEnvironmentFonts(true).linear-gradient support for background-image property. By @danfickle. Requested by @rja907.word-wrap: break-word. Now a word will not be broken unless it is too big for a line by itself. By @danfickle. Thanks for reporting and testing @mndzielski.<br/> tag. Thanks for reporting @fcorneli.lang() selector. Thanks for reporting and tracking down the bug @fungc.format tags. Only use format(truetype). Thanks for requesting @MichaelZaleskovsky and basis for implementation @syjer.section to default CSS. Thanks @syjer.lang and title attrbiutes and abbr tag for accessible PDFs. Thanks @Ignaciort91.img, svg and math elements.img tag: <img src="some.pdf" page="1" alt="Some alt text" />.218 followers · starred Jan 2022
34 followers · starred Nov 2022
101 followers · starred May 2019
7 followers · starred Oct 2022
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)!
See the code
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.
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.
Open HTML to PDF is based on Flying-saucer. Credit goes to the contributors of that project. Code will also be used from neoFlyingSaucer
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.
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.
page-break-inside: avoid constraint. Thanks for persisting @swillis12 and debugging @syjer.::before and ::after content. Should now be able to define a border around pseudo content correctly.table element to be positioned. Thanks @fcorneli.page and pages counters. Thanks for PR @fanthos.SECURITY RELEASE: This release was brought forward due to security releases of the PDFBOX and Batik dependencies.
println calls with log calls. Thanks @syjer for PR, @tfo for reporting.shape-rendering SVG CSS property. Thanks @syjer for PR, @RAlfoeldi for reporting.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.
SECURITY RELEASE
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.
target-text function for content property. Thanks for PR @BenjaminVega.IMPORTANT: #615 This is a bug fix release for an endless loop issue when using break-word with floating elements with a top/bottom margin.
SECURITY: #609 Updates Apache Batik SVG renderer to latest version to avoid security issue. If you are using this project to render untrusted SVGs (advised against), you should update immediately. Thanks a lot @halvorbmundal.
IMPORTANT: The fast renderer is now the default in preparation of removing the old slow renderer. To temporarily use the slow renderer, you can call the deprecated method builder.useSlowMode() (PDF output only).
IMPORTANT: #543 This version stays on PDFBOX version 2.0.20 due to a bug with non-breaking spaces in version 2.0.21. Please make sure version 2.0.21 is not on your classpath. This bug has been fixed in the upcoming 2.0.22.
baseUri arg to baseDocumentUri and improve javadoc to avoid confusion. Thanks for reporting @NehalDamania.word-wrap: break-word. Thanks for reporting, testing and investigating @swarl. Thanks for tests and debugging @rototor and @syjer.word-wrap: break-word. If you are using this feature, please upgrade promptly.word-wrap: break-word and soft hyphens. Thanks @rototor for PR, @syjer for analysis and @swarl for reporting.word-wrap: break-word and zero width boxes. Thanks @syjer for analysis and @AlexisCothenet for reporting.mailto: links or any other valid link. Thanks @syjer for PR and @mndzielski for reporting.direction CSS property. Thanks @AnanasPizza for reporting.IOException. Thanks for PR @leonorader.rem CSS unit. Thanks to @leonorader for reporting.content property. Thanks for requesting @Kuhlware.builder.useEnvironmentFonts(true).linear-gradient support for background-image property. By @danfickle. Requested by @rja907.word-wrap: break-word. Now a word will not be broken unless it is too big for a line by itself. By @danfickle. Thanks for reporting and testing @mndzielski.<br/> tag. Thanks for reporting @fcorneli.lang() selector. Thanks for reporting and tracking down the bug @fungc.format tags. Only use format(truetype). Thanks for requesting @MichaelZaleskovsky and basis for implementation @syjer.section to default CSS. Thanks @syjer.lang and title attrbiutes and abbr tag for accessible PDFs. Thanks @Ignaciort91.img, svg and math elements.img tag: <img src="some.pdf" page="1" alt="Some alt text" />.218 followers · starred Jan 2022
34 followers · starred Nov 2022
101 followers · starred May 2019
7 followers · starred Oct 2022