Issue: Missing Styles and Improper Font Loading with html2canvas
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:
html2canvas Result:
Hi I can help you sort out the issues for the $20 you posted on Upwork.
请问解决了吗
Hello, has this issue been resolved? If not, I can assist you in fixing it. price what ever you want to give. give me.
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.