PyMuPDF icon indicating copy to clipboard operation
PyMuPDF copied to clipboard

AttributeError: `'Annot' object has no attribute '__del__'`

Open karenli6 opened this issue 1 year ago • 0 comments

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

karenli6 avatar Feb 29 '24 23:02 karenli6