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,
)
| 759 | |
| 760 | |
| 761 | def 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) |
nothing calls this directly
no test coverage detected
searching dependent graphs…