私はcanvgを使用してsvg要素をキャンバスにレンダリングし、jspdfを使用してダウンロードしています。以下は私のコードです:
svgElement = jQuery('#svg');
canvas = jQuery('<canvas />').attr({
width: svgElement.width(),
height: svgElement.height()
}).get(0);
ctx = canvas.getContext("2d");
canvg(canvas, svgElement.outerHTML(), {ignoreMouse: true, ignoreAnimation: true});
imgData = canvas.toDataURL("image/png");
pdf = new jsPDF('landscape' , 'pt', [svgElement.height(), svgElement.width()]);
pdf.addImage(imgData, 'PNG', 0, 0);
pdf.save('download.pdf');
しかし、pdfの画像はぼやけて見え、元の画像ほど鮮明ではありません(背景の違いは無視してください):
おそらくcanvgがsvgをキャンバスにレンダリングするステップが原因だと思います。しかし、私はそれを修正する方法がわからない、誰かが助けることができますか?