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,
)
| 537 | |
| 538 | |
| 539 | def 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 | |
| 575 | def get_textbox( |
no test coverage detected
searching dependent graphs…