'Using multiple font family dynamically in jsPdf

I am using jsPdf library in angular application for PDF. Now I have a situation where I have to use Arabic font with some English font in same pdf report. Below is the piece of example code showing how I am using this before this requirements.

fontName = 'times'; //For example 
if (currentLocale === 'ar') {
  // add the font to jsPDF
  doc.addFileToVFS('ArabicFont-normal.ttf', ArabicFont);
  doc.addFileToVFS('ArabicFont-Bold-bold.ttf', ArabicFontBold);
  doc.addFont('ArabicFont-normal.ttf', 'ArabicFont', 'normal');
  doc.addFont('ArabicFont-Bold-bold.ttf', 'ArabicFont', 'bold');

  this.fontName = 'ArabicFont';
} else {
  this.fontName = 'helvetica';
}
doc.setFont(this.fontName);

doc.setFont(this.fontName, 'bold');
doc.setTextColor('#000000');
doc.text(`Some Text`, 10, 10);
doc.text(`Some Text 1`, 10, 10); //This is some Arabic text

I have both text and tables in the pdf where table may contain one or more Arabic columns as well. I wonder how can I use two font family at the same time. Any help would be appreciated. Thanks in advance!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source