When a font-face is defined in CSS and applied to an SVG text element it renders correctly within the browser but is ignored by html2canvas when creating an image. This is demonstrated in the following fiddle.
https://jsfiddle.net/y937mxnv/
+1
Also having this issue
Submitted a pull request, to bypass this for now you can use the following:
function svgToCanvas(targetElem) {
var svgElem = targetElem.getElementsByTagName("svg");
for (const node of svgElem) {
node.setAttribute("font-family", window.getComputedStyle(node, null).getPropertyValue("font-family"));
node.replaceWith(node);
}
}
svgToCanvas(yourElement);
which you call just before html2canvas(yourElement)
possible duplicate? #1463
Thanks @maximgeerinck ! Just a small addition, I was using a Google Font and I had to have the font served from the same domain as everything else...getting the font directly from google produced the same output as before even with your solution.
Most helpful comment
Thanks @maximgeerinck ! Just a small addition, I was using a Google Font and I had to have the font served from the same domain as everything else...getting the font directly from google produced the same output as before even with your solution.