Reputation: 36219
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:
These are all just times
font. Why is the font family not changing?
Upvotes: 11
Views: 45062
Reputation: 31
You have to use a standard font for jsPDF:
doc.setFont("Helvetica");
doc.setFontSize(10);
doc.setTextColor(10);
The 14 standard PDF fonts are as follows:
Courier
Courier-Bold
Courier-BoldOblique
Courier-Oblique
Helvetica
Helvetica-Bold
Helvetica-BoldOblique
Helvetica-Oblique
Symbol
Times-Roman
Times-Bold
Time-Italic
Time-BoldItalic
Upvotes: 3
Reputation: 639
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
Upvotes: 0
Reputation: 479
Actually you can use
doc.addFont()
For example:
doc.addFont('ArialMS', 'Arial', 'normal');
doc.setFont('Arial');
doc.text(50,150,'Hello World');
Upvotes: 11