Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jsPDF convert html to pdf: utf-8 works only with text, but not html

I need to convert html to pdf with jsPDF. It contains UTF-8 symbols (cyrillic). I used fontconverter to generate js-file for my custom font as written here: https://github.com/MrRio/jsPDF

So now example with text works like a charm.

var pdf = new jsPDF('p', 'pt', 'letter');
doc.setFont('PTSans');
doc.setFontSize(10);
doc.text("А ну чики брики и в дамки!", 10, 10);

And example with html ignores my custom font and exports incorrect symbols.

var pdf = new jsPDF('p', 'pt', 'letter');
doc.setFont('PTSans');
doc.setFontSize(10);
pdf.html( "<html>А ну чики брики и в дамки!</html>", { callback: function (pdf) {
    var iframe = document.createElement('iframe');
    iframe.setAttribute('style', 'position:absolute;right:0; top:0; bottom:0; height:100%; width:500px');
    document.body.appendChild(iframe);
    iframe.src = pdf.output('datauristring');
    }
});

What I need to do to export html to pdf with unicode symbols?

like image 968
Andrei Filipchyk Avatar asked Nov 07 '22 11:11

Andrei Filipchyk


1 Answers

I have not found how to solve this problem and created issue on jspdf github. And I've found that pdfmake.org correctly works with utf-8 symbols, so if you have same problems, use pdfmake.

like image 60
Andrei Filipchyk Avatar answered Nov 15 '22 08:11

Andrei Filipchyk