jsPDF将html转换为pdf:utf-8仅适用于文本,不适用于html

问题描述 投票:3回答:1

我需要使用jsPDF将html转换为pdf。它包含UTF-8符号(西里尔字母)。我使用fontconverter为我的自定义字体生成js文件,如下所示:https://github.com/MrRio/jsPDF

因此,带有文本的示例现在就像一种魅力。

var pdf = new jsPDF('p', 'pt', 'letter');
doc.setFont('PTSans');
doc.setFontSize(10);
doc.text("А ну чики брики и в дамки!", 10, 10);

带有html的示例将忽略我的自定义字体并导出不正确的符号。

var pdf = new jsPDF('p', 'pt', 'letter');
doc.setFont('PTSans');
doc.setFontSize(10);
pdf.html( "<html>А ну чики брики и в дамки!</html>", { callback: function (pdf) {
    var iframe = document.createElement('iframe');
    iframe.setAttribute('style', 'position:absolute;right:0; top:0; bottom:0; height:100%; width:500px');
    document.body.appendChild(iframe);
    iframe.src = pdf.output('datauristring');
    }
});

我需要做些什么来用Unicode符号将html导出为pdf?

javascript jspdf
1个回答
0
投票

我尚未找到如何解决此问题的方法,并在jspdf github上创建了问题。而且我发现pdfmake.org可以正确使用utf-8符号,因此,如果您遇到相同的问题,请使用pdfmake。

© www.soinside.com 2019 - 2024. All rights reserved.