When I run the following code:
from pypdf import PdfReader, PdfWriter
from pypdf.constants import AnnotationDictionaryAttributes
reader = PdfReader("f1040.pdf")
writer = PdfWriter()
writer.append(reader)
fields = []
for page in reader.pages:
writer.reattach_fields(page)
for annot in page.annotations:
annot = annot.get_object()
if annot[AnnotationDictionaryAttributes.Subtype] == "/Widget":
fields.append(annot)
if annot['/FT'] == "/Tx":
fieldName = annot["/T"]
writer.update_page_form_field_values(
writer.pages[page.page_number],
{fieldName: "Test"},
auto_regenerate=False,
)
print(fields)
I get this error:
dr = dr.get_object().get(“/Font”, DictionaryObject()).get_object()
AttributeError: ‘dict’ object has no attribute ‘get_object’
From what I can find, it appears to stem from PyPDF not finding the font element, but there aren’t a lot of resources on it.
Has anyone else encountered this?
New contributor
Brooks Watson is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.