在jspdf中添加自定义字体 [英] Add Custom font in jspdf

查看:2109
本文介绍了在jspdf中添加自定义字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在jsPDF中使用自定义字体,例如'Comic Sans MS'或'Calibri'字体。
我在这里发现了类似的问题,但是我的工作不正常。
我已经添加了最新的jspdf。我的代码如下:

i want to use custom font such as 'Comic Sans MS' or 'Calibri' font in jsPDF. i have found similar question here, but mine is not working. i already added the latest jspdf. and my code is like below :

        var doc = new jsPDF('p','mm','a4');

        doc.addFont('ComicSansMS', 'Comic Sans', 'normal','StandardEncoding');
        doc.setFont('Comic Sans');          
        doc.text(10, 10, "Lorem ipsum dolor sit amet!");
        doc.output('dataurl');

但是pdf结果的字体仍然是默认字体(不是漫画sans)。
并且没有错误。请帮忙...

but the pdf result's font is still the default font ( not comic sans ). and there is no error. Please help...

推荐答案

我找到了解决方案,

不要使用jspdf.js,而是使用debug.jspdf.js

don't use the jspdf.js, but use the debug.jspdf.js

然后在debug.jspdf.js中添加此代码

and after that add this code in the debug.jspdf.js

   API.addFont = function(postScriptName, fontName, fontStyle) {
       addFont(postScriptName, fontName, fontStyle, 'StandardEncoding');
   };

这篇关于在jspdf中添加自定义字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆