https://github.com/pymupdf/PyMuPDF/issues/2270
()
| 279 | page.apply_redactions() |
| 280 | |
| 281 | def test_2270(): |
| 282 | ''' |
| 283 | https://github.com/pymupdf/PyMuPDF/issues/2270 |
| 284 | ''' |
| 285 | path = os.path.abspath( f'{__file__}/../../tests/resources/test_2270.pdf') |
| 286 | with pymupdf.open(path) as document: |
| 287 | for page_number, page in enumerate(document): |
| 288 | for textBox in page.annots(types=(pymupdf.PDF_ANNOT_FREE_TEXT,pymupdf.PDF_ANNOT_TEXT)): |
| 289 | print("textBox.type :", textBox.type) |
| 290 | print(f"{textBox.rect=}") |
| 291 | print("textBox.get_text('words') : ", textBox.get_text('words')) |
| 292 | print("textBox.get_text('text') : ", textBox.get_text('text')) |
| 293 | print("textBox.get_textbox(textBox.rect) : ", textBox.get_textbox(textBox.rect)) |
| 294 | print("textBox.info['content'] : ", textBox.info['content']) |
| 295 | assert textBox.type == (2, 'FreeText') |
| 296 | assert textBox.get_text('words')[0][4] == 'abc123' |
| 297 | assert textBox.get_text('text') == 'abc123\n' |
| 298 | assert textBox.get_textbox(textBox.rect) == 'abc123' |
| 299 | assert textBox.info['content'] == 'abc123' |
| 300 | |
| 301 | # Additional check that Annot.get_textpage() returns a |
| 302 | # TextPage that works with page.get_text() - prior to |
| 303 | # 2024-01-30 the TextPage had no `.parent` member. |
| 304 | textpage = textBox.get_textpage() |
| 305 | text = page.get_text() |
| 306 | print(f'{text=}') |
| 307 | text = page.get_text(textpage=textpage) |
| 308 | print(f'{text=}') |
| 309 | print(f'{getattr(textpage, "parent")=}') |
| 310 | |
| 311 | # Check Annotation.get_textpage()'s <clip> arg. |
| 312 | clip = textBox.rect |
| 313 | clip.x1 = clip.x0 + (clip.x1 - clip.x0) / 3 |
| 314 | textpage2 = textBox.get_textpage(clip=clip) |
| 315 | text = textpage2.extractText() |
| 316 | print(f'With {clip=}: {text=}') |
| 317 | assert text == 'ab\n' |
| 318 | |
| 319 | |
| 320 | def test_2934_add_redact_annot(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…