pdf-lib Not saving the edited pdf when form gets filled

116 Views Asked by At

I am trying to fill a form using JavaScript and pdf-lib inside an Electron + Svelte application in Windows. When I call the following function const pdfBytes = await pdfDoc.save() after filling the form, the terminal does not give any error, but this is the Stacktrace I get in the console in the electron window:

Uncaught (in promise) Error: WinAnsi cannot encode "" (0x1f575)
    at Encoding.encodeUnicodeCodePoint (C:\Users\pmpls\Desktop\platform\src\node_modules\@pdf-lib\standard-fonts\lib\Encoding.js:23:23)
    at StandardFontEmbedder.encodeTextAsGlyphs (C:\Users\pmpls\Desktop\platform\src\node_modules\pdf-lib\cjs\core\embedders\StandardFontEmbedder.js:88:41)
    at StandardFontEmbedder.encodeText (C:\Users\pmpls\Desktop\platform\src\node_modules\pdf-lib\cjs\core\embedders\StandardFontEmbedder.js:28:27)
    at PDFFont.encodeText (C:\Users\pmpls\Desktop\platform\src\node_modules\pdf-lib\cjs\api\PDFFont.js:37:30)
    at splitOutLines (C:\Users\pmpls\Desktop\platform\src\node_modules\pdf-lib\cjs\api\text\layout.js:76:28)
    at exports.layoutMultilineText (C:\Users\pmpls\Desktop\platform\src\node_modules\pdf-lib\cjs\api\text\layout.js:110:22)
    at exports.defaultTextFieldAppearanceProvider (C:\Users\pmpls\Desktop\platform\src\node_modules\pdf-lib\cjs\api\form\appearances.js:240:31)
    at PDFTextField.updateWidgetAppearance (C:\Users\pmpls\Desktop\platform\src\node_modules\pdf-lib\cjs\api\form\PDFTextField.js:719:61)
    at PDFTextField.updateAppearances (C:\Users\pmpls\Desktop\platform\src\node_modules\pdf-lib\cjs\api\form\PDFTextField.js:713:18)
    at PDFTextField.defaultUpdateAppearances (C:\Users\pmpls\Desktop\platform\src\node_modules\pdf-lib\cjs\api\form\PDFTextField.js:689:14)

I get this error whether I use a custom font or don't. I have the last version of everything.

I tried different versions of the same library, without success. I also tried saving with and without flattening the form before, and I get the same result. I am really lost with this error, so I have not really tried anything different because I don't even know where to start from. Thank you for your patience.

0

There are 0 best solutions below