Skip to content

Textfield Widget not displaying value after updating. #563

@boukeas

Description

@boukeas

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.
Screenshot from 2020-07-20 22-56-41

The user manually enters new text in the field:
Screenshot from 2020-07-20 22-57-02

The new value is not displayed:
Screenshot from 2020-07-20 22-57-13

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions