Skip to content

v0.4.0: renderReady, resource precheck and pagination fixes

Latest

Choose a tag to compare

@mettta mettta released this 26 Nov 00:01
· 1 commit to main since this release

Upgrade notes

  • Renamed prefix. Attributes, service elements and classes now use the prefix html2pdf4doc instead of html2pdf. For example, mark the printable block with the html2pdf4doc attribute. Markup with the old html2pdf* names is still recognized (#173, #182, #183).
  • Custom CSS for generated elements. Elements and classes that html2pdf4doc creates are now named html2pdf4doc-*, not html2pdf-*. If your CSS targets the old names, update it.
  • Renamed options. data-print-width and data-print-height are now data-paper-width and data-paper-height. The old names still work and show a deprecation warning in the console (#166, #178).
  • Page boundaries may change. Several fixes remove empty pages and move page starts, so some documents get a different page count.

New

  • renderReady option. HTML2PDF4DOC.init() accepts a promise, a function that returns a promise, or an array of promises. html2pdf4doc waits for it after window.load and before it measures the page. Use it for async renderers such as Mermaid or PlantUML (#204, closes #201).
  • Resource precheck. Before measuring, html2pdf4doc waits for images, backgrounds, SVG and OBJECT resources, up to resourceTimeoutMs (default 2000). Each resource gets an html2pdf4doc-resource-status attribute. A resource that fails or times out produces a console warning and the html2pdf4doc:resource-issue event (#194).
  • Lazy content is measured. Lazy-loaded images, <picture> sources and content-visibility / contain blocks now take part in layout before pagination (#193).
  • Heuristic config selectors. Page break and no-hanging selectors from the config are treated as hints. :first-child, :last-child and :only-child matches are checked against the real content, including text nodes (#177).

Fixes

Page breaks and empty pages

  • No empty page when several page break rules match one element (#213).
  • No empty first page when the content starts with a zero-height element (#214).
  • No empty page when a SCRIPT or hidden element follows a page-break-after element (#212).
  • Empty spacer <p> elements no longer cause blank pages (#198).
  • page-break-before takes priority over no-hanging rules (#174).
  • Hidden and service elements no longer affect the choice of a page start (#196).
  • Collapsed margins of nested elements are reset at page boundaries (#197).

Tables and grids

  • A table row taller than a page no longer hangs the browser tab (#215).
  • A table footer (TFOOT) appears once, in the last part of the table (#211).
  • STYLE, SCRIPT, hidden INPUT or TR directly inside TABLE no longer stop the render (#208).
  • A grid row that spans many pages no longer triggers a false loop guard error (#205).

Images and text

  • Images at a page start no longer overflow the page (#195, #180, closes #179).
  • Text lines in Firefox no longer wrap differently after measurement (#199).

Config, header and footer

  • Length options such as "0" or "30" no longer take the value of another option. A unitless number means px (#210).
  • A page number template with only one number no longer stops the render (#209).
  • An empty preloader target no longer breaks the config (#168).
  • Minor artefacts in the header and footer areas are masked (#185).

Other

  • Smaller fixes and improvements (#172 and others).

Internal

  • Unified marker system (#187, #188), deferred DOM mutations (#198), styles refactor (#166).
  • End-to-end tests run in Firefox as well as Chrome (#191). CI tests Python 3.12 and 3.14 (#206, #207).