I am using WordPress Eventin plugin which embedded jsPDF. I have successfully added Chinese fonts SimHei.ttf to jsPDF like that:
const jsPDF = window.jspdf.jsPDF;
const doc = new jsPDF("p", "pt", "a4");
doc.addFont('https://server/path/Fonts/SimHei.ttf', 'SimHei', 'normal');
doc.setFont('SimHei');
doc.text("Octonyan loves jsPDF 中文字", 35, 25);
But I need to convert HTML to PDF like that:
let getContent = "<p>Octonyan loves jsPDF 中文字</p>";
doc.html(getContent, {
callback: function () {
doc.save(ticketname);
},
x: 10,
y: 10,
});
It does not display Chinese to PDF.
Anyone can help output HTML to PDF. Thank you!
- Downloaded original jsPDF to test
- Selected usable Chinese fonts
- Used fontconverter for following test
- Tried - doc.addFileToVFS("SimHei.ttf", myFont); It also works
Make sure that the
compressionparameter in jsPDF is set tofalsewhen you are creating the object of it calleddoc. Like this: