Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jsPDF cannot set font family

I cannot change the font family. This is directly off jsPDF website:

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:

enter image description here

These are all just times font. Why is the font family not changing?

like image 486
Kousha Avatar asked Dec 11 '15 21:12

Kousha


1 Answers

Actually you can use

doc.addFont()

For example:

doc.addFont('ArialMS', 'Arial', 'normal');
doc.setFont('Arial');
doc.text(50,150,'Hello World');
like image 198
BetterTeng Avatar answered Nov 20 '22 09:11

BetterTeng