pdf-lib's default fonts silently drop non-Latin characters from generated PDFs
A developer discovered that pdf-lib, a popular Node.js PDF generation library, silently deletes non-Western characters such as Polish or Czech letters when using its built-in standard fonts. The default fonts rely on WinAnsi (Windows-1252) encoding, which only covers Western European Latin characters, leaving names like Łódź truncated without any error or log warning. A common workaround of stripping unsupported characters to prevent crashes makes the problem worse, as it causes data loss that is invisible in logs and only detectable by visually inspecting the output. The fix is to embed a TrueType or OpenType font using pdf-lib's fontkit plugin, which supports the full Unicode range. Developers are also advised to enable font subsetting to keep file sizes small and to cache font file reads in serverless environments to reduce latency.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in