【问题标题】:I am having trouble in converting svg to PDF我在将 svg 转换为 PDF 时遇到问题
【发布时间】:2016-03-04 15:08:27
【问题描述】:

我正在尝试将 SVG 转换为工作正常的 PDF,但它返回给我一个空白 PDF。我怎样才能在 pdf 中实现我的 SVG?

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');
    });

【问题讨论】:

    标签: svg jspdf


    【解决方案1】:

    在此处使用 canvg https://stackoverflow.com/a/35788928/2090459 进行检查

    基本上,您需要获取 base64 图像才能添加到 PDF(jsPDF)中。如果我们有 canvas,我们可以使用 .toDataURL() 转换为 base64 字符串。

    在此处查看演示 http://jsfiddle.net/Purushoth/hvs91vpq/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-16
      • 2021-04-05
      • 2023-02-04
      • 2014-02-28
      • 2022-01-25
      • 1970-01-01
      相关资源
      最近更新 更多