The solution is to convert the fonts to base64 encoding and then import them. So, at the command prompt, using Linux / Cygwin, type:
base64 --wrap=0 Roboto-Black.ttf > Roboto-Black-Base64.ttf
This will create a new TTF file, which should contain all the text inside. If you use an external service, make sure there is no packaging. It should be one continuous block of text.
Then in the NodeJS code do:
let fs = require("fs"); let doc = new PDFDocument({bufferPages: true}); let filePath = path.join(__dirname, "fonts", "Roboto-Black-Base64.ttf"); let fileContents = fs.readFileSync(filePath, "utf8"); this.doc.registerFont(fontName, new Buffer(fileContents, "base64"));
Then your fonts will appear crystal clear. Reinforces this answer for giving me the keys I need.
Ryan Shillington 03 Oct '17 at 23:20 2017-10-03 23:20
source share