jsPDF生成pdf文件和中文编码 html转PDF

中文乱码问题

下载jspdf完整文件包https://github.com/MrRio/jsPDF,打开fontconverter/fontconverter.html,把windows中的ttf字体上传转换,生成字体的js文件,如msyh-normal.js,打开msyh-normal.js文件,拷贝addFont("msyh-normal.ttf", "msyh", "normal")。

导入js文件和jspdf.js文件

<script src="jspdf.min.js"></script>
<script src="msyh-normal.js"></script>
 

        var doc = new jsPDF();
        doc.addFont("msyh-normal.ttf", "msyh", "normal");
        doc.setFont('msyh');
        //pdf标题设置
        doc.text(20, 20, '你好!');

       doc.save("中文题目.pdf");

可正常显示中文。

猜你喜欢

转载自blog.csdn.net/kunga0814/article/details/81869183