Custom font faces in jsPDF?

后端 未结 6 700
無奈伤痛
無奈伤痛 2020-12-08 15:30

Is it possible to include custom fonts in jsPDF ?

With the basic library, if I console log \'doc.getFontList()\' I get:

Courier, Helvetica, Ti

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-08 16:07

    It seems to be a lot easier with the latest version of jsPDF (1.5.3):

    If you look in the folder jsPDF-master > fontconverter, there's a file fontconverter.html. Open in your browser and use the Browse... button to navigate to, and select your .ttf font file.

    Click 'Create'.

    The page will offer a "download" to be saved. This will produce a .js file called [something like] RopaSans-Regular-normal.js. This needs to be included in your page producing the PDF's. Personally, I've done it in the main page's header (and please note the order of the scripts):

    
    
    
    
    
    
    

    Now in your PDF generation method in js:

    doc.setFont('RopaSans-Regular');
    doc.setFontType('normal');
    

提交回复
热议问题