Reputation: 159
I am using JSPDF to export pdf. But I don't know how to add Vietnamese fonts into jspdf in order to export pdf with Vietnamese. Can you show me how to do it ? Thank you very much.
Upvotes: 1
Views: 1850
Reputation: 723
You should check their documentation, they've recently added UTF8 support, at this page you'll find the method addFont: https://rawgit.com/MrRio/jsPDF/master/docs/jsPDF.html#addFont
To add a custom font file to pdfjs you could check out this: https://rawgit.com/MrRio/jsPDF/master/docs/module-vFS.html#~addFileToVFS
Here is an example: https://codepen.io/bocko/pen/RyGBKg
const pdf = new jsPDF({
unit: 'pt',
orientation: 'p',
format: [pdfSize, pdfSize],
//lineHeight: 1.2
});
// define custom font
pdf.addFileToVFS("ConsolasHex.ttf", [base64 encoding of font])
// add custom font to file
pdf.addFont("ConsolasHex.ttf", "ConsolasHex", "Bold");
pdf.setFont("ConsolasHex","Bold");
pdf.setFontSize(12);
Upvotes: 1