Changelog

Lazy-loaded images

The new lazyLoad parameter scrolls through the page before the PDF is generated, so images that load on scroll are included.

NewAPI

Many pages load images only when they scroll into view, with loading="lazy" or a JavaScript loader. A PDF is generated without scrolling, so images further down such a page could be missing or show a placeholder.

Set lazyLoad to true to scroll through the page before the PDF is generated, the way a visitor would. Images and content that load on scroll are loaded, and the page is scrolled back to the top before it is rendered. It came with the upgrade to Chromium 156.

curl --fail --show-error --output page.pdf --request POST \
  --url https://api.html2pdf.app/v1/generate \
  --header 'Content-Type: application/json' \
  --header 'X-API-Key: <your-api-key>' \
  --data '{ "html": "https://example.com", "lazyLoad": true }'

How it works

  • Native lazy images — images marked loading="lazy" are loaded straight away.
  • JavaScript loaders — the page is scrolled from top to bottom so that they see every element, and after the last scroll it waits for the images that started loading.
  • Endless pages — scrolling stops at the bottom of the page once it stops growing, or after 12 seconds at most, so a page that keeps loading more content as you scroll still finishes.

Things to know

  • It is off by default, because scrolling adds time on long pages.
  • Effects the page runs while scrolling can appear in the PDF, such as a header that appears on scroll, or an animation or a carousel caught part way.
  • For content that arrives later still, also set waitFor: the wait starts after the scroll.

See Lazy-loaded images and Parameters in the documentation.