question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Convert html to pdf: utf-8 works only with text, but not html (unicode/cyrillic not working)

See original GitHub issue

I’m opening this issue again.

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 (from https://github.com/MrRio/jsPDF/blob/master/examples/js/russian.js)

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?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:12
  • Comments:30 (2 by maintainers)

github_iconTop GitHub Comments

9reactions
Rui-Jesuscommented, Nov 16, 2020

In my case, using the version 2.1, setting the font style on the html element like so: <html style="font-family: PTSans;">А ну чики брики и в дамки!</html> and importing the fonts according to https://www.devlinpeck.com/tutorials/jspdf-custom-font#:~:text=Adding Custom Fonts to jsPDF,of your desired font file.&text=Once you have your .,to this jsPDF Font Converter. worked for me when using an html element reference instead of using a raw html string.

8reactions
HackbrettXXXcommented, Oct 20, 2020

Please try setting the font name also in the html markup. E.g.

<html style="font-family: PTSans;">А ну чики брики и в дамки!</html>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Convert html to pdf: utf-8 works only with text, but not ... - GitHub
I'm opening this issue again. I need to convert html to pdf with jsPDF. It contains UTF-8 symbols (cyrillic).
Read more >
jsPDF convert html to pdf: utf-8 works only with text, but not html
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...
Read more >
Changing an HTML page to Unicode - W3C
Answer · Step 1: Save the data as UTF-8 · Step 2: Declare the encoding in your page · Step 3: Ensure that...
Read more >
How to make Cyrillic characters display properly when ...
I have a problem with PDF fonts. I am generating PDF from HTML and that worked fine on my local machine, which has...
Read more >
MySQL 8.0 Reference Manual :: 10.10.1 Unicode Character Sets
utf8mb4 : A UTF-8 encoding of the Unicode character set using one to four ... based only on the Unicode Collation Algorithm (UCA)...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found