pdf-lib is silently deleting characters from your users' data
I generate invoices in a Node serverless function with pdf-lib . It is a good library. It also quietly destroyed a client's company name, threw nothing, logged nothing, and produced a PDF that opened perfectly. The name was Łódź Sp. z o.o. The invoice said ód Sp. z o.o. Here is what is going on, because it will hit anyone generating documents from user-supplied text. The standard 14 fonts are…
The article discusses a bug in the pdf-lib library that silently removes characters from user-supplied data in generated PDF documents. The issue occurs when trying to draw non-Latin-1 characters, such as Ł, outside the 1990s WinAnsi encoding table. pdf-lib throws an error for unsupported characters, but the crash is not logged or visible in logs.
To resolve the issue, developers should embed a TrueType or OpenType font instead of relying on the default 1990s encoding table. This ensures the document can display a wider range of characters without silent data loss. The article also highlights the importance of caching font reads in serverless functions to avoid unnecessary latency.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.