我很难使用 JSPDF 将 SVG 文件转换为 PDF。我在这里工作了以下代码。
var doc = new jsPDF();
var test = $.get('amChart.svg', function(svgText){
// console.log(svgText);
var svgAsText = new XMLSerializer().serializeToString(svgText.documentElement);
console.log(svgAsText);
doc.addSVG(svgAsText, 20, 20, doc.internal.pageSize.width - 20*2)
//console.log(doc);
// Save the PDF
doc.output('datauri');
});
我从这里得到这个脚本所以答案 https://stackoverflow.com/questions/23340610/how-to-create-easily-a-pdf-from-a-svg-with-jspdf.仅其结果空白PDF.When i console.log(doc)
在输出之前它会显示结果。但它不会导致PDF...
我也在工作SVGEMENTOPDF函数由此GitHub 网址 https://github.com/CBiX/svgToPdf.js/我也在这段代码中工作过。
// I recommend to keep the svg visible as a preview
var svg = $('#container > svg').get(0);
// you should set the format dynamically, write [width, height] instead of 'a4'
var pdf = new jsPDF('p', 'pt', 'a4');
svgElementToPdf(svg, pdf, {
scale: 72/96, // this is the ratio of px to pt units
removeInvalid: true // this removes elements that could not be translated to pdf from the source svg
});
pdf.output('datauri'); // use output() to get the jsPDF buffer
但我无法实现它..请告诉我...如何解决这个问题JSPDF