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?
Finally I've decided to use pdfmake, it works correctly with utf-8 symbols.
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
@AFilipchyk, how does it work ?
I need to create a PDF file from react component in Macedonian language(also cyrillic).
Can it do the job for me ?
This issue is stale because it has been open 90 days with no activity. It will be closed soon. Please comment/reopen if this issue is still relevant.
@AFilipchyk for what it worth, you need to set font-family style in your HTML element or string.
@AFilipchyk oh really how does it work!! Can you please share how you pass UTF-8 code using pdfmake
Most helpful comment
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