eKoopmans / html2pdf.js

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

fix: Using canvas as a direct source #701

Closed eKoopmans closed 1 week ago

eKoopmans commented 1 week ago

It's supposed to be possible to use a canvas as a direct source, with either of:

  1. html2pdf().from(canvas).save() etc.
  2. html2pdf().set({ canvas: canvas }).save() etc.

But there were two errors preventing this from working:

  1. Typo in getType when using toLowerCase(), meaning the .from() approach didn't work
  2. Missing pageSize initialization in toPdf, meaning both approaches didn't work

This PR should solve the issue - added the all-tags_canvas.pdf snapshot test to verify the fix.

Closes #699