| 543 | |
| 544 | |
| 545 | def test_4182(): |
| 546 | path = os.path.normpath(f'{__file__}/../../tests/resources/test_4182.pdf') |
| 547 | with pymupdf.open(path) as document: |
| 548 | page = document[0] |
| 549 | dict_ = page.get_text('dict') |
| 550 | linelist = [] |
| 551 | for block in dict_['blocks']: |
| 552 | if block['type'] == 0: |
| 553 | paranum = block['number'] |
| 554 | if 'lines' in block: |
| 555 | for line in block.get('lines', ()): |
| 556 | for span in line['spans']: |
| 557 | if span['text'].strip(): |
| 558 | page.draw_rect(span['bbox'], color=(1, 0, 0)) |
| 559 | linelist.append([paranum, span['bbox'], repr(span['text'])]) |
| 560 | pixmap = page.get_pixmap() |
| 561 | path_out = os.path.normpath(f'{__file__}/../../tests/resources/test_4182_out.png') |
| 562 | pixmap.save(path_out) |
| 563 | if platform.system() != 'Windows': # Output on Windows can fail due to non-utf8 stdout. |
| 564 | for l in linelist: |
| 565 | print(l) |
| 566 | path_expected = os.path.normpath(f'{__file__}/../../tests/resources/test_4182_expected.png') |
| 567 | pixmap_diff = gentle_compare.pixmaps_diff(path_expected, pixmap) |
| 568 | path_diff = os.path.normpath(f'{__file__}/../../tests/resources/test_4182_diff.png') |
| 569 | pixmap_diff.save(path_diff) |
| 570 | rms = gentle_compare.pixmaps_rms(path_expected, pixmap) |
| 571 | print(f'{rms=}') |
| 572 | assert rms < 0.01 |
| 573 | |
| 574 | |
| 575 | def test_4179(): |