-
Notifications
You must be signed in to change notification settings - Fork 664
Closed
Labels
Description
Describe the bug (mandatory)
A TextField widget can be added to a pdf programmatically. However, when a user loads the pdf into a viewer and manually updates the text in the field, the new value is not displayed.
To Reproduce (mandatory)
import fitz
doc = fitz.Document()
page = doc.newPage()
page.insertTextbox(fitz.Rect(10, 10, 200, 30), "Some text")
widget = fitz.Widget()
widget.rect = fitz.Rect(10, 40, 200, 60)
widget.field_type = fitz.ANNOT_WG_TEXT
widget.text_fontsize = 16
widget.fill_color = (0.8, 0.8, 0.8)
widget.field_name = "textfield-1"
widget.field_value = "form text"
annot = doc[0].addWidget(widget)
doc.save("test.pdf", clean=True)
doc.close()
Screenshots (optional)
This is how the text field is displayed originally.

The user manually enters new text in the field:

The new value is not displayed:

Your configuration (mandatory)
- Ubuntu 18.04
- Python 3.6.9
- PyMuPDF version 1.16.17
Additional context (optional)
In the past, I have used pdfrw to fill in the forms in a pdf and I had encountered a similar problem. It was solved using the NeedAppearances flag:
# bug fix from https://github.com/pmaupin/pdfrw/issues/84
PdfReader(input_pdf).Root.AcroForm.update(PdfDict(NeedAppearances=PdfObject('true')))