-
-
Notifications
You must be signed in to change notification settings - Fork 614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.setText() on a form field keeps font-size but overwrites pre-set font and font-color #1597
Comments
I was having an issue with it myself, but then reading the PDFTextField.setText specification revealed this:
Meaning this behaviour is intended. I was able to work my way around this by explicitly updating the form back to the font I needed (luckily it was one of the standard fonts) using PDFForm.updateFieldAppearances:
I had to do this after I edited my form's fields, right before saving the doc. |
What were you trying to do?
I created a form PDF with several form fields. I then set the text for each form field in front-end java script. This works fine, but the preset font and font color are overwritten when set a new text while font size seems to remain correct
How did you attempt to do it?
const response = await fetch('//myPath');
const existingPdfBytes = await response.arrayBuffer();
const pdfDoc = await PDFLib.PDFDocument.load(existingPdfBytes);
const pdfForm = pdfDoc.getForm();
pdfForm.getTextField('kid-first').setText(kidFirstName);
What actually happened?
text is changed correctly
font size remains pre-set size for the form field
font and font color are overwritten default font and black
What did you expect to happen?
text is changed correctly
form field's pre-set font, font-size and font-color remain unchanged
How can we reproduce the issue?
Thanks
Version
https://cdn.jsdelivr.net/npm/pdf-lib/dist/pdf-lib.js
What environment are you running pdf-lib in?
Browser
Checklist
Additional Notes
No response
The text was updated successfully, but these errors were encountered: