foliojs / pdfkit

A JavaScript PDF generation library for Node and the browser
http://pdfkit.org/
MIT License
9.84k stars 1.15k forks source link

How do I use the fonts that come with my system? #1515

Closed luckymore closed 4 months ago

luckymore commented 4 months ago

Question

My scenario is that after generating a pdf on the server side, the user downloads it locally and views it using the system's Chinese fonts. like STBaoliTC-Regular

Is it possible to do that?

Description

When I try to do this, it reports an error no such file or directory, open 'STBaoliTC-Regular'

doc.font('STBaoliTC-Regular')

Code sample

const doc = new PDFDocument({
  size: [595, 842],
})
doc.pipe(fs.createWriteStream('output.pdf'))
doc.font('STBaoliTC-Regular')
doc.text('你好,世界!')
doc.end()

Your environment

blikblum commented 4 months ago

Is it possible to do that?

No. You have to embed the font at server side using doc.registerFont