Andrei Filipchyk
Andrei Filipchyk

Reputation: 182

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?

Upvotes: 6

Views: 2693

Answers (1)

Andrei Filipchyk
Andrei Filipchyk

Reputation: 182

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.

Upvotes: 2

Related Questions