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

Function get_text_blocks

src_classic/utils.py:500–536  ·  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: Page,
    clip: rect_like = None,
    flags: OptInt = None,
    textpage: TextPage = None,
    sort: bool = False,
)

Source from the content-addressed store, hash-verified

498
499
500def get_text_blocks(
501 page: Page,
502 clip: rect_like = None,
503 flags: OptInt = None,
504 textpage: TextPage = None,
505 sort: bool = False,
506) -> list:
507 """Return the text blocks on a page.
508
509 Notes:
510 Lines in a block are concatenated with line breaks.
511 Args:
512 flags: (int) control the amount of data parsed into the textpage.
513 Returns:
514 A list of the blocks. Each item contains the containing rectangle
515 coordinates, text lines, block type and running block number.
516 """
517 CheckParent(page)
518 if flags is None:
519 flags = (
520 TEXT_PRESERVE_WHITESPACE
521 | TEXT_PRESERVE_IMAGES
522 | TEXT_PRESERVE_LIGATURES
523 | TEXT_MEDIABOX_CLIP
524 )
525 tp = textpage
526 if tp is None:
527 tp = page.get_textpage(clip=clip, flags=flags)
528 elif getattr(tp, "parent") != page:
529 raise ValueError("not a textpage of this page")
530
531 blocks = tp.extractBLOCKS()
532 if textpage is None:
533 del tp
534 if sort is True:
535 blocks.sort(key=lambda b: (b[3], b[0]))
536 return blocks
537
538
539def get_text_words(

Callers 1

get_textFunction · 0.70

Calls 3

CheckParentFunction · 0.85
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…