Search code examples
javascriptfontsjspdf

Add Custom font in jspdf


i want to use custom font such as 'Comic Sans MS' or 'Calibri' font in jsPDF. i have found similar question here, but mine is not working. i already added the latest jspdf. and my code is like below :

        var doc = new jsPDF('p','mm','a4');

        doc.addFont('ComicSansMS', 'Comic Sans', 'normal','StandardEncoding');
        doc.setFont('Comic Sans');          
        doc.text(10, 10, "Lorem ipsum dolor sit amet!");
        doc.output('dataurl');

but the pdf result's font is still the default font ( not comic sans ). and there is no error. Please help...


Solution

  • i have found the solution,

    don't use the jspdf.js, but use the debug.jspdf.js

    and after that add this code in the debug.jspdf.js

       API.addFont = function(postScriptName, fontName, fontStyle) {
           addFont(postScriptName, fontName, fontStyle, 'StandardEncoding');
       };