Please look at the fiddle example. I am less knowledge on working with pdf fonts. I am using pdfkit to generate the pdf. I am trying to load the japanese fonts but no luck. I followed most of the articles from stackoverflow but i am not successful in writing japanese text to the pdf.
var doc = new PDFDocument();
var stream = doc.pipe(blobStream());
// draw some text
doc.fontSize(25)
.text("hello world", 100, 80);
var oReq = new XMLHttpRequest();
oReq.open("GET", "//fonts.gstatic.com/ea/mplus1p/v1/Mplus1p-Thin.ttf", true);
oReq.responseType = "arraybuffer";
oReq.onload = function (oEvent) {
var arrayBuffer = oReq.response; // Note: not oReq.responseText
if (arrayBuffer) {
doc.registerFont('OpenSans', arrayBuffer)
doc.fontSize(25);
doc.font('OpenSans').text('こんにちは世界')
}
};
oReq.send(null);
// end and display the document in the iframe to the right
doc.end();
stream.on('finish', function () {
document.getElementById('myiframe').src = stream.toBlobURL('application/pdf');
console.log(stream.toBlobURL('application/pdf'))
document.getElementById('spnmessage').innerText = "can't load the pdf in iframe in the jsfiddle. You can open the pdf through console"
});
Here is the fiddle