Search code examples
javascriptjspdf

Javascript jsPDF UTF-8 character problems


I have a problem

I am having utf-8 character problem when converting in jspdf

    window.jsPDF = window.jspdf.jsPDF;
    applyPlugin(window.jsPDF);

    function downPdf () {
        let doc = new jsPDF()
        console.log('asd')
        const elementHTML = document.querySelector('#pdf')
        doc.html(elementHTML, {
            callback: function (doc) {
                // Save the PDF
                doc.save('sample-document.pdf')
            },
            x: 15,
            y: 15,
            width: 170, // target width in the PDF document
            windowWidth: 650 // window width in CSS pixels
        })
    }

no problem downloading and working

The only problem is that a few characters such as "ğ", "ş", "ı" have problems while converting.


Solution

  • As @KJ said, fonts need to be added, I chose to use the plugin called html2topdf to avoid dealing with it.

    and I solved my problem in this way, there is no such problem in that library