MCPcopy Create free account
hub / github.com/pymupdf/PyMuPDF / get_text_blocks

Function get_text_blocks

src/utils.py:52–83  ·  view source on GitHub ↗

Return the text blocks on a page. Notes: Lines in a block are concatenated with line breaks. Args: flags: (int) control the amount of data parsed into the textpage. Returns: A list of the blocks. Each item contains the containing rectangle coordinates, te

(
    page: pymupdf.Page,
    clip: rect_like = None,
    flags: OptInt = None,
    textpage: pymupdf.TextPage = None,
    sort: bool = False,
)

Source from the content-addressed store, hash-verified

50
51
52def get_text_blocks(
53 page: pymupdf.Page,
54 clip: rect_like = None,
55 flags: OptInt = None,
56 textpage: pymupdf.TextPage = None,
57 sort: bool = False,
58) -> list:
59 """Return the text blocks on a page.
60
61 Notes:
62 Lines in a block are concatenated with line breaks.
63 Args:
64 flags: (int) control the amount of data parsed into the textpage.
65 Returns:
66 A list of the blocks. Each item contains the containing rectangle
67 coordinates, text lines, running block number and block type.
68 """
69 pymupdf.CheckParent(page)
70 if flags is None:
71 flags = pymupdf.TEXTFLAGS_BLOCKS
72 tp = textpage
73 if tp is None:
74 tp = page.get_textpage(clip=clip, flags=flags)
75 elif getattr(tp, "parent") != page:
76 raise ValueError("not a textpage of this page")
77
78 blocks = tp.extractBLOCKS()
79 if textpage is None:
80 del tp
81 if sort:
82 blocks.sort(key=lambda b: (b[3], b[0]))
83 return blocks
84
85
86def get_text_words(

Callers 1

get_textFunction · 0.70

Calls 2

extractBLOCKSMethod · 0.80
get_textpageMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…