Hopding / pdf-lib

Create and modify PDF documents in any JavaScript environment
https://pdf-lib.js.org
MIT License
6.74k stars 645 forks source link

Original font is not mantained when a form is filled #1538

Open gioppoluca opened 10 months ago

gioppoluca commented 10 months ago

What were you trying to do?

I'm using the acroform's fields to fill an existing PDF module. The resulting module looses the original font of the module and gets Helvetica.

How did you attempt to do it?

field.setText();

What actually happened?

The resulting module looses the original font of the module and gets Helvetica.

What did you expect to happen?

The field keeps its original font. Also I'm unable to retrieve the used font from any available API.

How can we reproduce the issue?

I use LibreOffice to create a module, assign a different font and create the PDF. Also tried to modify the PDF with acrobat and altering the font again, with no luck. You can see the PDF here: https://github.com/gioppoluca/sheet-export/blob/master/mappings/dnd5e/experimental/latest/5e-model.pdf

Version

1.17.1

What environment are you running pdf-lib in?

Browser

Checklist

Additional Notes

Is there an API to retrieve the original font used?

dcbr commented 8 months ago

I encountered the same issue and found following solution when the font was previously embedded using pdf-lib. See also my comment here.

// Get embedded font using code from above comment
field.setText(newText);
field.updateAppearances(font);