MCPcopy Index your code
hub / github.com/pymupdf/PyMuPDF / test_extendable_textpage

Function test_extendable_textpage

tests/test_textextract.py:664–846  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

662
663
664def test_extendable_textpage():
665
666 # 2025-01-28:
667 #
668 # We can create a pdf with two pages whose text is adjacent when stitched
669 # together vertically:
670 #
671 # Page 1:
672 #
673 # aaaa
674 #
675 # bbbb
676 # cccc
677 #
678 # dddd
679 #
680 # Page 2:
681 #
682 # eeee
683 #
684 # ffff
685 # gggg
686 #
687 # hhhh
688 #
689 #
690 # Create a textpage for both of these pages. Then when extracting text,
691 # we need to get (specifically the `dddd` and `eeee` sequences need to be
692 # treated as the same block):
693 #
694 # aaaa
695 #
696 # bbbb
697 # cccc
698 #
699 # dddd
700 # eeee
701 #
702 # ffff
703 # gggg
704 #
705 # hhhh
706 #
707 print()
708
709 path = os.path.normpath(f'{__file__}/../../tests/test_extendable_textpage.pdf')
710 with pymupdf.open(filetype='pdf') as document:
711 document.new_page()
712 document.new_page()
713 page0 = document[0]
714 page1 = document[1]
715 y = 100
716 line_height = 9.6
717 for i in range(4):
718 page0.insert_text((100, y+line_height), 'abcd'[i] * 16)
719 page1.insert_text((100, y+line_height), 'efgh'[i] * 16)
720 y += line_height
721 if i%2 == 0:

Callers

nothing calls this directly

Calls 8

extractDICTMethod · 0.95
extractTextMethod · 0.95
extractBLOCKSMethod · 0.95
new_pageMethod · 0.80
insert_textMethod · 0.45
draw_rectMethod · 0.45
saveMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…