diff --git a/src/__init__.py b/src/__init__.py index 1256fc450..96d986202 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -10670,8 +10670,10 @@ def annots(self, types=None): annot_xrefs = [a[0] for a in self.annot_xrefs() if a[1] in types and a[1] not in skip_types] for xref in annot_xrefs: annot = self.load_annot(xref) - annot._yielded=True - yield annot + # In #4928, annot can be None, which we need to ignore. + if annot: + annot._yielded=True + yield annot def apply_redactions( page: 'Page', diff --git a/tests/resources/test_4944.pdf b/tests/resources/test_4944.pdf new file mode 100644 index 000000000..8e9d02669 Binary files /dev/null and b/tests/resources/test_4944.pdf differ diff --git a/tests/test_annots.py b/tests/test_annots.py index 122968291..e48e4dd61 100644 --- a/tests/test_annots.py +++ b/tests/test_annots.py @@ -718,3 +718,24 @@ def draw_rectangle(rect, c, w): document.save(path_out) print(f' {path=}.') print(f'{path_out=}.') + + +def test_4944(): + path = os.path.normpath(f'{__file__}/../../tests/resources/test_4944.pdf') + path_out = os.path.normpath(f'{__file__}/../../tests/test_4944_out.pdf') + print() + with pymupdf.open(path) as document: + page = document[0] + print(f'{page.rotation=}') + print(f'{page.rotation_matrix=}') + print(f'{page.transformation_matrix=}') + text_json = page.get_text('rawjson') + #print(text_json) + + page.add_redact_annot(page.rect) + page.apply_redactions(text=pymupdf.PDF_REDACT_TEXT_REMOVE) + document.save(path_out) + print(repr(page.get_text())) + + text_json = page.get_text('rawjson') + #print(text_json) diff --git a/tests/test_general.py b/tests/test_general.py index fd063ffa2..c3ab644c3 100644 --- a/tests/test_general.py +++ b/tests/test_general.py @@ -2213,13 +2213,12 @@ def test_4907(): display_list = page.get_displaylist(annots=False) text_page = display_list.get_textpage() + def test_4928(): path = os.path.normpath(f'{__file__}/../../tests/resources/test_4928.pdf') with pymupdf.open(path) as document: - try: - document.scrub() - except Exception as e: - print(f'Ignoring expected exception: {e}') + document.scrub() + def test_4902(): print()