Extract text from a page or an annotation. This is a unifying wrapper for various methods of the pymupdf.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 swit
(
page: pymupdf.Page,
option: str = "text",
*,
clip: rect_like = None,
flags: OptInt = None,
textpage: pymupdf.TextPage = None,
sort: bool = False,
delimiters=None,
tolerance=3,
)
| 399 | |
| 400 | |
| 401 | def get_text( |
| 402 | page: pymupdf.Page, |
| 403 | option: str = "text", |
| 404 | *, |
| 405 | clip: rect_like = None, |
| 406 | flags: OptInt = None, |
| 407 | textpage: pymupdf.TextPage = None, |
| 408 | sort: bool = False, |
| 409 | delimiters=None, |
| 410 | tolerance=3, |
| 411 | ): |
| 412 | """Extract text from a page or an annotation. |
| 413 | |
| 414 | This is a unifying wrapper for various methods of the pymupdf.TextPage class. |
| 415 | |
| 416 | Args: |
| 417 | option: (str) text, words, blocks, html, dict, json, rawdict, xhtml or xml. |
| 418 | clip: (rect-like) restrict output to this area. |
| 419 | flags: bit switches to e.g. exclude images or decompose ligatures. |
| 420 | textpage: reuse this pymupdf.TextPage and make no new one. If specified, |
| 421 | 'flags' and 'clip' are ignored. |
| 422 | |
| 423 | Returns: |
| 424 | the output of methods get_text_words / get_text_blocks or pymupdf.TextPage |
| 425 | methods extractText, extractHTML, extractDICT, extractJSON, extractRAWDICT, |
| 426 | extractXHTML or etractXML respectively. |
| 427 | Default and misspelling choice is "text". |
| 428 | """ |
| 429 | formats = { |
| 430 | "text": pymupdf.TEXTFLAGS_TEXT, |
| 431 | "html": pymupdf.TEXTFLAGS_HTML, |
| 432 | "json": pymupdf.TEXTFLAGS_DICT, |
| 433 | "rawjson": pymupdf.TEXTFLAGS_RAWDICT, |
| 434 | "xml": pymupdf.TEXTFLAGS_XML, |
| 435 | "xhtml": pymupdf.TEXTFLAGS_XHTML, |
| 436 | "dict": pymupdf.TEXTFLAGS_DICT, |
| 437 | "rawdict": pymupdf.TEXTFLAGS_RAWDICT, |
| 438 | "words": pymupdf.TEXTFLAGS_WORDS, |
| 439 | "blocks": pymupdf.TEXTFLAGS_BLOCKS, |
| 440 | } |
| 441 | option = option.lower() |
| 442 | assert option in formats |
| 443 | if option not in formats: |
| 444 | option = "text" |
| 445 | if flags is None: |
| 446 | flags = formats[option] |
| 447 | |
| 448 | if option == "words": |
| 449 | return get_text_words( |
| 450 | page, |
| 451 | clip=clip, |
| 452 | flags=flags, |
| 453 | textpage=textpage, |
| 454 | sort=sort, |
| 455 | delimiters=delimiters, |
| 456 | ) |
| 457 | if option == "blocks": |
| 458 | return get_text_blocks( |
nothing calls this directly
no test coverage detected
searching dependent graphs…