Jspdf: Set font does not set font

Created on 11 Jan 2017  路  2Comments  路  Source: MrRio/jsPDF

Are you using the latest version of jsPDF?
Version 1.3.2 Built on 2016-09-30T20:33:17.116Z

Have you tried using jspdf.debug.js?
Yes.

Steps to reproduce
Adding a custom google font
pdf.addFont("Raleway", "Raleway", "normal");
pdf.setFont("Raleway", "normal");

What I saw
PDF uses Times New Roman

What I expected
PDF using Raleway

jspdf.debug.js, line 790, function _getFont

  fontName = fontName !== undefined ? fontName : fonts[activeFontKey].fontName;
  fontStyle = fontStyle !== undefined ? fontStyle : fonts[activeFontKey].fontStyle;

  if (fontName !== undefined) {
    fontName = fontName.toLowerCase();
  }

  switch (fontName) {
  case 'sans-serif':
  case 'verdana':
  case 'arial':
  case 'helvetica':
    fontName = 'helvetica';
    break;
  case 'fixed':
  case 'monospace':
  case 'terminal':
  case 'courier':
    fontName = 'courier';
    break;
   case 'serif':
   case 'cursive':
   case 'fantasy':
   default:
     fontName = 'times';
     break;
   }

   try {
     // get a string like 'F3' - the KEY corresponding tot he font + type combination.
     key = fontmap[fontName][fontStyle];
   } catch (e) {}

If the custom font is not inside the switch, it will always fall under "times", despite being in the font list. Since we can't access the switch from the outside, custom fonts will fail.

Most helpful comment

All 2 comments

I am having the same issue I am trying to use Clear Sans

Was this page helpful?
0 / 5 - 0 ratings

Related issues

centurianii picture centurianii  路  4Comments

Pinank picture Pinank  路  3Comments

palmoni picture palmoni  路  4Comments

glaier picture glaier  路  3Comments

MelanieCroce picture MelanieCroce  路  4Comments