eKoopmans / html2pdf.js

Client-side HTML-to-PDF rendering using pure JS.
MIT License
3.92k stars 1.37k forks source link

Layout Shift When Converting HTML to PDF #666

Open therealtgd opened 9 months ago

therealtgd commented 9 months ago

Description: I am experiencing a layout shift issue when using the html2pdf.js library to convert HTML to PDF in a React application. The layout shift occurs when I trigger the conversion process.

Environment:

Steps to Reproduce:

  1. Include the html2pdf.js library in a React project.
  2. Trigger the HTML to PDF conversion process using the library.

Expected Behavior: The HTML should be converted to PDF without causing any layout shifts or disturbances in the original layout.

Actual Behavior: The conversion process causes a layout shift in the original HTML layout, which is not the expected behavior.

itsic7 commented 9 months ago

I can confirm similar misbehaviour.

When converting a relatively complex HTML element, an unexpected spacing shift occurs. What makes troubleshooting more difficult, however, is the fact that the shifts do not occur with every conversion. For example, out of 6 conversions, 3 PDFs are generated with the correct spacing; on the 3 other PDFs, the spacing of the individual components of the affected HTML element is incorrect. On top, the incorrect distances are never the same, but always different.

Does anyone have any idea what could be causing this sporadic error during conversion and whether there is a solution for it?