-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Description
In EmbeddedFont#embed (src/pdfkit, line ~32447 in the built bundle), the code assumes this.font.postscriptName is always a string:
const name = tag + '+' + this.font.postscriptName?.replaceAll(' ', '_');
However, fontkit's readString() returns a raw Uint8Array when TextDecoder doesn't support the requested encoding (e.g. x-mac-roman, utf-16be). This happens on Hermes (React Native), which only supports utf-8 and utf-16le.
This causes a TypeError: replaceAll is not a function at PDF generation time.
Suggested fix
const _psName = this.font.postscriptName;
const _psStr = typeof _psName === 'string'
? _psName
: _psName instanceof Uint8Array
? Array.from(_psName, b => String.fromCharCode(b)).join('')
: String(_psName || '');
const name = tag + '+' + _psStr.replace(/ /g, '_');This handles all three cases (string, Uint8Array, null/undefined) and also replaces .replaceAll() with .replace(/ /g, '_') for broader engine compatibility.
Your environment
- pdfkit: 0.17.2
- pdfmake: 0.3.3
- React Native: 0.81.4
- Expo: 54.0.10
- React: 19.1.0
- JS Engine: Hermes
- Node: 20.19.5
- Platform: iOS / Android
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels