question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: WinAnsi cannot encode

See original GitHub issue

Hi 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:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
MarcelloTheArcanecommented, Oct 29, 2020

@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:

string.split('\n').forEach(paragraph => page.drawText(paragraph))
4reactions
Hopdingcommented, Aug 5, 2020

@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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found