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

Function get_text_words

src_classic/utils.py:539–572  ·  view source on GitHub ↗

Return the text words as a list with the bbox for each word. Args: flags: (int) control the amount of data parsed into the textpage. delimiters: (str,list) characters to use as word delimiters Returns: Word tuples (x0, y0, x1, y1, "word", bno, lno, wno).

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

Source from the content-addressed store, hash-verified

537
538
539def get_text_words(
540 page: Page,
541 clip: rect_like = None,
542 flags: OptInt = None,
543 textpage: TextPage = None,
544 sort: bool = False,
545 delimiters=None,
546) -> list:
547 """Return the text words as a list with the bbox for each word.
548
549 Args:
550 flags: (int) control the amount of data parsed into the textpage.
551 delimiters: (str,list) characters to use as word delimiters
552
553 Returns:
554 Word tuples (x0, y0, x1, y1, "word", bno, lno, wno).
555 """
556 CheckParent(page)
557 if flags is None:
558 flags = TEXT_PRESERVE_WHITESPACE | TEXT_PRESERVE_LIGATURES | TEXT_MEDIABOX_CLIP
559
560 tp = textpage
561 if tp is None:
562 tp = page.get_textpage(clip=clip, flags=flags)
563 elif getattr(tp, "parent") != page:
564 raise ValueError("not a textpage of this page")
565
566 words = tp.extractWORDS(delimiters)
567 if textpage is None:
568 del tp
569 if sort is True:
570 words.sort(key=lambda w: (w[3], w[0]))
571
572 return words
573
574
575def get_textbox(

Callers 1

get_textFunction · 0.70

Calls 3

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