Awais
Awais

Reputation: 37

I am having trouble in converting svg to PDF

I am trying to convert SVG to PDF which is working fine but it is returning me a blank PDF. How can i achieve my SVG in pdf?

var doc = new jsPDF('p', 'pt', 'letter');
    var test = $.get('/BarCodeSmallTag.svg', function (svgText) {
        var svgAsText = new XMLSerializer().serializeToString(svgText.documentElement);
        doc.addSVG(svgAsText, 20, 20, doc.internal.pageSize.width - 20 * 2)

        // Save the PDF
        doc.save('TestSVG.pdf');
    });

Upvotes: 0

Views: 686

Answers (1)

Purushoth
Purushoth

Reputation: 2793

Check here to do that using canvg https://stackoverflow.com/a/35788928/2090459

Basically you need get base64 image to add into PDF(jsPDF). If we have canvas we can convert to base64 string using .toDataURL().

Check the demo here http://jsfiddle.net/Purushoth/hvs91vpq/

Upvotes: 1

Related Questions