html2pdf.js icon indicating copy to clipboard operation
html2pdf.js copied to clipboard

Support `trimPages` mode to create PDF pages of variable length

Open tsufiev opened this issue 3 months ago • 0 comments

When generating PDF documents which

  1. are meant only for viewing from screen and
  2. at the same time contain a lot of pictures, infographics, etc which cannot be easily broken between pages of fixed height

it is very convenient to have pages of varying height.

The whole approach would work the following way:

  1. Set an initial page to be big enough to fit as many content as there possible can be on one page (say, format: [841.89 * 1.4, 3370.39 * 3])
  2. Continue calling html2pdf worker in a loop, rendering one page at a time.
  3. Once .toPdf() is invoked, it trims that huge fixed-height page to an actual content height.

tsufiev avatar Oct 15 '25 15:10 tsufiev