Like: nodejs pdfkit output Japanese or Chinese

I am running a nodejs + expressjs + mongodb project, I need to get data from mongodb and then write it to pdf file and then send expressjs. everything seems fine except that the data is a Japanese letter and the encoding is messed up. I am using pdfkit to generate a pdf file, for example:

var doc = new PDFDocument();

doc.info['Title'] = profile.firstName + " " + profile.lastName;

doc.fillColor('black')
    .text(profile.firstName + " " + profile.lastName, {
    paragraphGap: 10,
    indent: 20,
    align: 'justify',
    columns: 2
});

      

then the meta information of the file and the only line of content shows: "kf Y˛" which should be: "æ­Š ć€§éƒŽ"

So, is there a way to set the encoding in the pdfkit? or some work around?

+1


source to share


1 answer


PDFKit supports embedding of TrueType (.ttf), TrueType Collection (.ttc), and Datafork TrueType (.dfont) font files. (source: http://pdfkit.org/docs/text.html#fonts )

Download Japanese TrueType font (.ttf) here http://www.freejapanesefont.com/ipaex-gothic/



# Using a TrueType font (.ttf)
doc.font('fonts/ipaexg.ttf').text('æ­Šć€§éƒŽ')

      

+1


source







All Articles