我使用的是jspdf (2.3.1)库。当我尝试使用addSvgAsImage ()方法改变svg元素的背景颜色时,背景颜色没有改变,并且总是显示黑色背景。有人能帮上忙吗。

exportPdf() {
const doc = new jsPDF('p', 'pt', 'a3');
doc.addSvgAsImage('<svg width="200" height="200" style="background-color: red"><polygon
points="100,10 40,198 190,78 10,78 160,198" style="fill:lime;stroke:purple;stroke-width:5;fill-
rule:evenodd;"/></svg>', 10, 50, 200 ,200);
doc.html(document.getElementById("exportPage"), {callback: function (doc) {
doc.save('test.pdf');
},x: 10, y: 250});
} 发布于 2021-05-12 21:40:57
CSS属性background-color实际上是一个超文本标记语言。jsPDF的SVG解析器很可能不支持这一点。请尝试将其替换为矩形。
exportPdf() {
const doc = new jsPDF('p', 'pt', 'a3');
doc.addSvgAsImage('<svg width="200" height="200"><rect width="200" height="200" fill="red"/><polygon
points="100,10 40,198 190,78 10,78 160,198" style="fill:lime;stroke:purple;stroke-width:5;fill-
rule:evenodd;"/></svg>', 10, 50, 200 ,200);
doc.html(document.getElementById("exportPage"), {callback: function (doc) {
doc.save('test.pdf');
},x: 10, y: 250});
} https://stackoverflow.com/questions/67500519
复制相似问题