MCPcopy Index your code
hub / github.com/danfickle/openhtmltopdf

github.com/danfickle/openhtmltopdf @openhtmltopdf-parent-1.0.10

Chat with this repo
repository ↗ · DeepWiki ↗ · release openhtmltopdf-parent-1.0.10 ↗ · + Follow
6,196 symbols 20,437 edges 420 files 1,220 documented · 20% updated 2y ago★ 2,158317 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

build

OPEN HTML TO PDF

PDF screenshot of OpenHTMLtoPDF

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

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.
  • Flowing columns are not implemented. 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 (release pending)

  • #551 SECURITY Fix near-infinite loop for very deeply nested content with page-break-inside: avoid constraint. 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 ::before and ::after content. 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 table element to be positioned. Thanks @fcorneli.
  • #727 Allow the use of an initial page number for page and pages counters. 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 println calls with log calls. Thanks @syjer for PR, @tfo for reporting.
  • #708 Allow shape-rendering SVG 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 Correct layout of ordered lists in RTL direction. Thanks for PR @johnnyaug.
  • #658 Implement target-text function for content property. Thanks for PR @BenjaminVega.
  • #647 Fix race condition in setting up logger in multi-threaded environments. Thanks for PR @syjer.
  • #638 Ability to plug-in external resource control based on resource type and url. Thanks for original PR @syjer.
  • #628 Use enhanced image embedding methods from PDF-BOX. Thanks for PR @rototor and your work in PDF-BOX implementing this.
  • #627 Fix regression where a null font style was causing NPE. Thaks for PR @rototor.
  • #338 Implement read-only radio button group. Thanks for investigating, reporting and patience @ThoSchCon, @aleks-shbln, @dmitry-weirdo, @syjer and @paulito-bandito.

1.0.6 (2020-December-22)

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. + #624 Update PDFBOX to 2.0.22 and pdfbox-graphics2d to 0.30. Thanks @rototor. + #467 Prevent possibility of CSS import loop. + #621 Allow spaces in data uris. Thanks @syjer.

1.0.5 (2020-November-30)

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.

  • #544 Code to create a website for pre-canned PDF templates in thymeleaf and raw XHTML format. Check out the template website to preview templates.
  • #533 Barcode plugin. Very useful PR supplied by @syjer. Barcode plugin docs.
  • #521 Move Java2D image output to fast renderer and general improvements. Java2D image output docs.
  • 9ffd0e #568 Filter out problematic characters that are visible in some fonts but should not be such as soft-hyphen. Thanks @StephanSchrader.
  • #587 Fix for white-space: nowrap cutting off instead of wrapping. Thanks @vipcxj for finally fixing via PR.
  • #577 Add foreground PDF drawer plugin (useful especially for watermarks). Thanks @rototor for PR and @sillen102 for persisting.
  • #566 Rename baseUri arg to baseDocumentUri and improve javadoc to avoid confusion. Thanks for reporting @NehalDamania.
  • 801780 Update junit test dependency to 4.13.1 to avoid security scanner warnings (the specific security problem did not impact

Extension points exported contracts — how you extend this code

IPdfBoxElementWithShapedLinks (Interface)
All Elements which can have a shaped image map implement this [8 implementers]
openhtmltopdf-pdfbox/src/main/java/com/openhtmltopdf/pdfboxout/PdfBoxLinkManager.java
Styleable (Interface)
All objects appearing the layout tree must implement this interface. It can roughly be thought of as a styled element ( [6 …
openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/Styleable.java
FSPage (Interface)
(no doc) [6 implementers]
openhtmltopdf-java2d/src/main/java/com/openhtmltopdf/java2d/api/FSPage.java
Java2DBuilderConfig (Interface)
(no doc) [9 implementers]
openhtmltopdf-examples/src/main/java/com/openhtmltopdf/visualtest/Java2DVisualTester.java
DataProvider (Interface)
(no doc)
openhtmltopdf-templates/src/main/java/com/openhtmltopdf/templates/DataGenerator.java
PdfBoxReplacedElement (Interface)
(no doc) [19 implementers]
openhtmltopdf-pdfbox/src/main/java/com/openhtmltopdf/pdfboxout/PdfBoxReplacedElement.java
InlinePaintable (Interface)
An interface which indicates that a box is able to paint itself in an inline context. This includes lines and layed out [6 …
openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/InlinePaintable.java
FSPageProcessor (Interface)
(no doc) [4 implementers]
openhtmltopdf-java2d/src/main/java/com/openhtmltopdf/java2d/api/FSPageProcessor.java

Core symbols most depended-on inside this repo

get
called by 574
openhtmltopdf-core/src/main/java/com/openhtmltopdf/extend/FSCacheEx.java
add
called by 458
openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/displaylist/PagedBoxCollector.java
getStyle
called by 448
openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/Styleable.java
put
called by 354
openhtmltopdf-core/src/main/java/com/openhtmltopdf/extend/FSCacheEx.java
log
called by 192
openhtmltopdf-core/src/main/java/com/openhtmltopdf/util/XRLog.java
equals
called by 184
openhtmltopdf-core/src/main/java/com/openhtmltopdf/css/constants/CSSName.java
addValue
called by 181
openhtmltopdf-core/src/main/java/com/openhtmltopdf/css/constants/IdentValue.java
getHeight
called by 170
openhtmltopdf-core/src/main/java/com/openhtmltopdf/extend/FSImage.java

Shape

Method 5,389
Class 696
Interface 77
Enum 34

Languages

Java100%

Modules by API surface

openhtmltopdf-core/src/main/java/com/openhtmltopdf/css/parser/property/PrimitivePropertyBuilders.java221 symbols
openhtmltopdf-examples/src/test/java/com/openhtmltopdf/visualregressiontests/VisualRegressionTest.java161 symbols
openhtmltopdf-core/src/main/java/com/openhtmltopdf/css/style/CalculatedStyle.java152 symbols
openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/Box.java151 symbols
openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/BlockBox.java151 symbols
openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/PageBox.java106 symbols
openhtmltopdf-core/src/main/java/com/openhtmltopdf/newtable/TableBox.java106 symbols
openhtmltopdf-pdfbox/src/main/java/com/openhtmltopdf/pdfboxout/PdfBoxSlowOutputDevice.java105 symbols
openhtmltopdf-pdfbox/src/main/java/com/openhtmltopdf/pdfboxout/PdfBoxAccessibilityHelper.java105 symbols
openhtmltopdf-core/src/main/java/com/openhtmltopdf/layout/Layer.java103 symbols
openhtmltopdf-core/src/main/java/com/openhtmltopdf/css/newmatch/Condition.java96 symbols
openhtmltopdf-pdfbox/src/main/java/com/openhtmltopdf/pdfboxout/PdfBoxFastOutputDevice.java91 symbols

For agents

$ claude mcp add openhtmltopdf \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact