I struggled to convert SVG files to PDF using JSPDF. Here I worked in the following code.
var doc = new jsPDF();
var test = $.get('amChart.svg', function(svgText){
var svgAsText = new XMLSerializer().serializeToString(svgText.documentElement);
console.log(svgAsText);
doc.addSVG(svgAsText, 20, 20, doc.internal.pageSize.width - 20*2)
doc.output('datauri');
});
I get this script from this SO answer . His results are only blank pdf . When I console.log(doc)before the exit will be the results shown. But this will not result in a PDF ...
And I also work in the SVGELEMENTOPDF function from this GITHUB URL , and I also worked in this code.
var svg = $('#container > svg').get(0);
var pdf = new jsPDF('p', 'pt', 'a4');
svgElementToPdf(svg, pdf, {
scale: 72/96,
removeInvalid: true
});
pdf.output('datauri');
But I can’t achieve this. And kindly advise me ... How to solve this problem in JSPDF