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

Function get_text

src_classic/utils.py:761–854  ·  view source on GitHub ↗

Extract text from a page or an annotation. This is a unifying wrapper for various methods of the TextPage class. Args: option: (str) text, words, blocks, html, dict, json, rawdict, xhtml or xml. clip: (rect-like) restrict output to this area. flags: bit switches to

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

Source from the content-addressed store, hash-verified

759
760
761def get_text(
762 page: Page,
763 option: str = "text",
764 clip: rect_like = None,
765 flags: OptInt = None,
766 textpage: TextPage = None,
767 sort: bool = False,
768 delimiters=None,
769):
770 """Extract text from a page or an annotation.
771
772 This is a unifying wrapper for various methods of the TextPage class.
773
774 Args:
775 option: (str) text, words, blocks, html, dict, json, rawdict, xhtml or xml.
776 clip: (rect-like) restrict output to this area.
777 flags: bit switches to e.g. exclude images or decompose ligatures.
778 textpage: reuse this TextPage and make no new one. If specified,
779 'flags' and 'clip' are ignored.
780
781 Returns:
782 the output of methods get_text_words / get_text_blocks or TextPage
783 methods extractText, extractHTML, extractDICT, extractJSON, extractRAWDICT,
784 extractXHTML or etractXML respectively.
785 Default and misspelling choice is "text".
786 """
787 formats = {
788 "text": fitz.TEXTFLAGS_TEXT,
789 "html": fitz.TEXTFLAGS_HTML,
790 "json": fitz.TEXTFLAGS_DICT,
791 "rawjson": fitz.TEXTFLAGS_RAWDICT,
792 "xml": fitz.TEXTFLAGS_XML,
793 "xhtml": fitz.TEXTFLAGS_XHTML,
794 "dict": fitz.TEXTFLAGS_DICT,
795 "rawdict": fitz.TEXTFLAGS_RAWDICT,
796 "words": fitz.TEXTFLAGS_WORDS,
797 "blocks": fitz.TEXTFLAGS_BLOCKS,
798 }
799 option = option.lower()
800 if option not in formats:
801 option = "text"
802 if flags is None:
803 flags = formats[option]
804
805 if option == "words":
806 return get_text_words(
807 page,
808 clip=clip,
809 flags=flags,
810 textpage=textpage,
811 sort=sort,
812 delimiters=delimiters,
813 )
814 if option == "blocks":
815 return get_text_blocks(
816 page, clip=clip, flags=flags, textpage=textpage, sort=sort
817 )
818 CheckParent(page)

Callers

nothing calls this directly

Calls 13

CheckParentFunction · 0.85
RectClass · 0.85
extractJSONMethod · 0.80
extractRAWJSONMethod · 0.80
extractDICTMethod · 0.80
extractRAWDICTMethod · 0.80
extractHTMLMethod · 0.80
extractXMLMethod · 0.80
extractXHTMLMethod · 0.80
extractTextMethod · 0.80
get_text_wordsFunction · 0.70
get_text_blocksFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…