I use canvg for set svg file in canvas. All is ok when I set svg url:
var canvas = doc.getCanvas(num);
var context = canvas.getContext('2d');
context.drawSvg("http://localhost:8084/manual.svg", 0, 0, width, height);
But when I try to write (it doesn't work):
context.drawSvg("data:image/svg+xml,"+svg, 0, 0, width, height);
where variable svg get manual.svg content.
img.src = "data:image/svg+xml;base64,"+btoa(svgContent);
context.drawImage(img, 0, 0, width, height);
it's one variant to solve the problem.
来源:https://stackoverflow.com/questions/12899053/draw-svg-to-canvas-with-canvg