Convert html to pdf: utf-8 works only with text, but not html (unicode/cyrillic not working)
See original GitHub issueI’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:
- Created 3 years ago
- Reactions:12
- Comments:30 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.Please try setting the font name also in the html markup. E.g.