pdf-lib icon indicating copy to clipboard operation
pdf-lib copied to clipboard

Original font is not mantained when a form is filled

Open gioppoluca opened this issue 2 years ago • 1 comments

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

  • [X] My report includes a Short, Self Contained, Correct (Compilable) Example.
  • [X] I have attached all PDFs, images, and other files needed to run my SSCCE.

Additional Notes

Is there an API to retrieve the original font used?

gioppoluca avatar Nov 04 '23 16:11 gioppoluca

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);

dcbr avatar Dec 31 '23 13:12 dcbr