Skip to content

AttributeError: 'Annot' object has no attribute '__del__' #3216

@karenli6

Description

@karenli6

Description of the bug

We are trying to detect any type of widget and delete it. When we perform the operation page.delete_widget(w) it throws AttributeError: 'Annot' object has no attribute '__del__'

Sample Pdf:

How to reproduce the bug

To Reproduce

PyMuPDF 1.23.25: Python bindings for the MuPDF 1.23.10 library (rebased implementation).
Python 3.11 running on darwin (64-bit).

import fitz
class ModifyPDF:
    def __init__(self, input_path, outputFilePath):
        self.pdfFilePath = input_path
        self.outputFilePath = outputFilePath

    def remove_input_fields(self):
        docs = fitz.open(self.pdfFilePath)
        for page in docs:
            w = page.first_widget
            while w:
                w = page.delete_widget(w)

        docs.save(self.outputFilePath, garbage=3, deflate=True, pretty=True)
        docs.close()


if __name__ == "__main__":
    filePath = "example_form.pdf"
    outputPath = "output.pdf"
    PdfFunction = ModifyPDF(filePath, outputPath)
    PdfFunction.remove_input_fields()

Expected behavior

Widgets should be deleted.

Error output trace:

Screenshot 2024-02-29 at 3 56 54 PM

PyMuPDF version

1.23.25

Operating system

MacOS

Python version

3.11

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions