Hetfield Joe
Hetfield Joe

Reputation: 1453

How to: nodejs pdfkit output japanese or chinese

I'm doing my nodejs + expressjs + mongodb project, I need fetch data from mongodb and then write it to pdf file, then send out by expressjs. everything seems fine except that the data is Japanese letter, and the encoding messed-up. I'm using pdfkit for creating pdf file, like this:

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-info of the file and the only line of the content shows: "kf Y’˛" which is should be : "武 大郎"

so, is there any way to set the encoding in pdfkit? or some work around?

Upvotes: 2

Views: 3748

Answers (1)

neythz
neythz

Reputation: 74

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

Download a Japanese Font in TrueType (.ttf) format here http://www.freejapanesefont.com/ipaex-gothic/

# Using a TrueType font (.ttf)
doc.font('fonts/ipaexg.ttf').text('武大郎')

Upvotes: 2

Related Questions