Error: WinAnsi cannot encode
See original GitHub issueHi noticed in my error logs the following error.
Error: WinAnsi cannot encode "
"
at Encoding.encodeUnicodeCodePoint (/app/node_modules/@pdf-lib/standard-fonts/lib/Encoding.js:22:23)
at StandardFontEmbedder.encodeTextAsGlyphs (/app/node_modules/pdf-lib/cjs/core/embedders/StandardFontEmbedder.js:82:41)
at StandardFontEmbedder.widthOfTextAtSize (/app/node_modules/pdf-lib/cjs/core/embedders/StandardFontEmbedder.js:35:27)
at PDFFont.widthOfTextAtSize (/app/node_modules/pdf-lib/cjs/api/PDFFont.js:53:30)
at splitIfBigger (/app/api/services/shipping-logs/shipping-logs.class.js:192:35)
at Object.get (/app/api/services/shipping-logs/shipping-logs.class.js:141:5)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async /app/api/services/orders/hooks/orders.send-email.js:194:37
I assume it is because someone tried to add a non-existing font by copy and pasting test into an input field. What could be the solution?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
I am getting Error when i Use Arabic latter in PDF-LIP , TypeError
I have used many npm to encode the Arabic letter but it does not work. I am getting this TypeError: font must be...
Read more >@pdf-lib/standard-fonts - npm
Metrics for the Standard 14 PDF fonts and their encodings. Latest version: 1.0.0, last published: 2 years ago.
Read more >Re-encode non-embedded fonts to WinAnsi where possible
The text is re-encoded to WinAnsi Encoding. We would like to duplicate this, however at present I am unable to see how Distiller...
Read more >pdf-lib/README.md - UNPKG
So trying to draw it on a page with the standard Helvetica font will throw the following error: 1255. 1256, ```. 1257, Error:...
Read more >Cantoo-pdf-lib NPM - npm.io
However, most of them can only create documents, they cannot modify existing ones. ... Error: WinAnsi cannot encode "Ω" (0x03a9) at Encoding.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@MarcGodard That’s the Unicode character for a newline (I know because it just happened to me).
You can try replacing it with a space character, or else split the text and add the paragraphs separately:
@MarcGodard You can access the characters supported by a given font with
PDFFont.getCharacterSet(). You could then filter out any input characters that are not supported by your font before attempting to draw text with it. You could also substitute them, throw errors, or any number of things. Really depends on your use case.I hope this helps!