javascript jsPDF 无法设置字体系列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34232813/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jsPDF cannot set font family
提问by Kousha
I cannot change the font family. This is directly off jsPDF website:
我无法更改字体系列。这是直接关闭 jsPDF网站:
var doc = new jsPDF();
doc.text(20, 20, 'This is the default font.');
doc.setFont("courier");
doc.setFontType("normal");
doc.text(20, 30, 'This is courier normal.');
doc.setFont("times");
doc.setFontType("italic");
doc.text(20, 40, 'This is times italic.');
doc.setFont("helvetica");
doc.setFontType("bold");
doc.text(20, 50, 'This is helvetica bold.');
doc.setFont("courier");
doc.setFontType("bolditalic");
doc.text(20, 60, 'This is courier bolditalic.');
But here is what is printed for:
但这是打印的内容:
These are all just times
font. Why is the font family not changing?
这些都只是times
字体。为什么字体系列没有改变?
回答by BetterTeng
Actually you can use
其实你可以用
doc.addFont()
For example:
例如:
doc.addFont('ArialMS', 'Arial', 'normal');
doc.setFont('Arial');
doc.text(50,150,'Hello World');
回答by Em An
I was having the same problem I have come up with the best solution It is to use the latest version of the library With jspdf.debug.js file usage You'll find them here: https://cdnjs.com/libraries/jspdf
我遇到了同样的问题我想出了最好的解决方案它是使用最新版本的库与 jspdf.debug.js 文件用法你会在这里找到它们:https://cdnjs.com/libraries/jspdf