html2canvas icon indicating copy to clipboard operation
html2canvas copied to clipboard

Issue: Missing Styles and Improper Font Loading with html2canvas

Open adilvalizada opened this issue 1 year ago • 4 comments

I am encountering an issue while using html2canvas in my React project. When I try to capture screenshots of a specific page, some styles are missing, and fonts are not rendering properly in the generated image. The output screenshot doesn't match the original page design. For example, in the generated image, I noticed:

Font styles are incorrect compared to the original page (fonts are not properly loaded). Certain styles, such as specific colors and visual elements, are either missing or improperly rendered. I have attached a comparison of the original design and the output generated by html2canvas for reference.

Original Design: Screenshot 2024-09-17 at 17 16 16

html2canvas Result: Screenshot 2024-09-17 at 16 29 30

adilvalizada avatar Sep 17 '24 13:09 adilvalizada

Hi I can help you sort out the issues for the $20 you posted on Upwork.

Akighir-Aondohemba avatar Sep 18 '24 14:09 Akighir-Aondohemba

请问解决了吗

888wangshuai avatar Sep 25 '24 08:09 888wangshuai

Hello, has this issue been resolved? If not, I can assist you in fixing it. price what ever you want to give. give me.

Rashid-Aly avatar Oct 02 '24 06:10 Rashid-Aly

If you're using SVGs, make sure you're using embedded fonts that are base64 encoded and aren't linked, for example, add something like this to your chart SVGs:

<defs>
  <style>
    @font-face {
      font-family: 'Roboto';
      font-style: normal;
      font-weight: 400;
      font-stretch: 100%;
      src: url(data:font/woff2;base64,...) format('woff2');
      unicode-range: ...;
    }
  </style>
</defs>

If you're using Google fonts, you can get the font-face definitions easily here: https://amio.github.io/embedded-google-fonts/

Unfortunately, it's going to severely bloat the size of your SVGs, so you want to make sure you only get the minimum required font-faces.

TSIA-SN avatar Mar 11 '25 17:03 TSIA-SN