Ensure identical output across text extractions.
()
| 625 | |
| 626 | |
| 627 | def test_2553(): |
| 628 | """Ensure identical output across text extractions.""" |
| 629 | verbose = 0 |
| 630 | doc = pymupdf.open(f"{scriptdir}/resources/test_2553.pdf") |
| 631 | page = doc[0] |
| 632 | |
| 633 | # extract plain text, build set of all characters |
| 634 | list1 = page.get_text() |
| 635 | set1 = set(list1) |
| 636 | |
| 637 | # extract text blocks, build set of all characters |
| 638 | list2 = page.get_text(sort=True) # internally uses "blocks" |
| 639 | set2 = set(list2) |
| 640 | |
| 641 | # extract textbox content, build set of all characters |
| 642 | list3 = page.get_textbox(page.rect) |
| 643 | set3 = set(list3) |
| 644 | |
| 645 | def show(l): |
| 646 | ret = f'len={len(l)}\n' |
| 647 | for c in l: |
| 648 | cc = ord(c) |
| 649 | if (cc >= 32 and cc < 127) or c == '\n': |
| 650 | ret += c |
| 651 | else: |
| 652 | ret += f' [0x{hex(cc)}]' |
| 653 | return ret |
| 654 | |
| 655 | if verbose: |
| 656 | print(f'list1:\n{show(list1)}') |
| 657 | print(f'list2:\n{show(list2)}') |
| 658 | print(f'list3:\n{show(list3)}') |
| 659 | |
| 660 | # all sets must be equal |
| 661 | assert set1 == set2 |
| 662 | assert set1 == set3 |
| 663 | |
| 664 | # With mupdf later than 1.23.4, this special page contains no invalid |
| 665 | # Unicodes. |
| 666 | # |
| 667 | print(f'Checking no occurrence of 0xFFFD, {pymupdf.mupdf_version_tuple=}.') |
| 668 | assert chr(0xFFFD) not in set1 |
| 669 | |
| 670 | def test_2553_2(): |
| 671 | doc = pymupdf.open(f"{scriptdir}/resources/test_2553-2.pdf") |
nothing calls this directly
no test coverage detected
searching dependent graphs…