MatthewHerbst / react-to-print

Print React components in the browser. Supports Chrome, Safari, Firefox and EDGE
MIT License
2.06k stars 221 forks source link

img tag adds much more to the final PDF size than it should #716

Closed Dysos closed 2 months ago

Dysos commented 2 months ago

I'm having some issues with the filesize of the download PDFs when using this library. I've narrowed it down to the usage of the <img/> tag - which strangely adds a lot more to the final file size of the PDF than it "should".

Changing nothing else in the document to be downloaded, adding a single img tag, pointing to a src with a filesize of 288kB, adds just over 7MB to the size of the downloaded PDF.

Is this an error, or is there something I'm not getting about the conversion from HTML to PDF? Because it seems extraordinarily high.

Otherwise a great library 👌

MatthewHerbst commented 2 months ago

Hello! Apologies for the delayed response, and thanks for the kind words.

This library does not convert anything into a PDF. What we do is call window.print within an iframe that has your content to print.

The PDF is being generated by the browser (Chrome, Firefox, etc). This is likely an issue with how the browser is constructing the PDF.

Dysos commented 2 months ago

Thank you very much. I will look into how the browser does this conversion then, to try and reduce the filesize 👌

MatthewHerbst commented 2 months ago

Please let us know what you find, many folks who use this library are likely interested in this topic!