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

See original GitHub issue

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:closed
  • Created 4 years ago
  • Comments:7

github_iconTop GitHub Comments

11reactions
vvarhcommented, Jan 28, 2020

I use convert file PTSans.ttf https://rawgit.com/MrRio/jsPDF/master/fontconverter/fontconverter.html add in file PTSans-normal.js import jsPDF from 'jspdf'

And in my App used jsPDF

import 'assets/fonts/PTSans-normal.js';
import jsPDF from 'jspdf';

const doc = new jsPDF();

doc.setFont('PTSans'); // set custom font
doc.text('Привет мир!', 10, 10) // It's working
5reactions
AFilipchykcommented, Jan 8, 2020

Finally I’ve decided to use pdfmake, it works correctly with utf-8 symbols.

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 >
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...
Read more >
(M)HTML to PDF conversion does not support Unicode
Hello, I'm trying to convert a .mht/.html file with Aspose. ... InputEncoding = “UTF-8” solves the encoding problem, but the images are not...
Read more >
PHP htmlspecialchars() Function - W3Schools
Example. Convert the predefined characters "<" (less than) and ">" (greater than) to HTML entities: <?php $str = "This is some <b>bold</b> text.";...
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