How do I create easily a PDF from an SVG with jsPDF?

前端 未结 5 1408
逝去的感伤
逝去的感伤 2020-12-05 16:21

I\'m trying to create a pdf but I have some SVG pictures. I found information about this problem, but I just have to use JavaScript, that\'s to say, no jQuery.

I fou

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-05 16:42

    I got this plugin working, but only with SVG file from the tests and the I saw in the doc that only PATHs are supported :(

    There is already the issue on github https://github.com/MrRio/jsPDF/issues/384

    If paths are ok for here is my code (it's more or less the code from the tests):

    function demoSvgDocument() {
        var doc = new jsPDF();
        var test = $.get('013_sillysvgrenderer.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');
        });
    }       
    

    Another point to consider, you have to run all examples on a server. Otherwise you won't see any results probably because of the security

提交回复
热议问题