Return the text blocks on a page. Notes: Lines in a block are concatenated with line breaks. Args: flags: (int) control the amount of data parsed into the textpage. Returns: A list of the blocks. Each item contains the containing rectangle coordinates, te
(
page: Page,
clip: rect_like = None,
flags: OptInt = None,
textpage: TextPage = None,
sort: bool = False,
)
| 498 | |
| 499 | |
| 500 | def get_text_blocks( |
| 501 | page: Page, |
| 502 | clip: rect_like = None, |
| 503 | flags: OptInt = None, |
| 504 | textpage: TextPage = None, |
| 505 | sort: bool = False, |
| 506 | ) -> list: |
| 507 | """Return the text blocks on a page. |
| 508 | |
| 509 | Notes: |
| 510 | Lines in a block are concatenated with line breaks. |
| 511 | Args: |
| 512 | flags: (int) control the amount of data parsed into the textpage. |
| 513 | Returns: |
| 514 | A list of the blocks. Each item contains the containing rectangle |
| 515 | coordinates, text lines, block type and running block number. |
| 516 | """ |
| 517 | CheckParent(page) |
| 518 | if flags is None: |
| 519 | flags = ( |
| 520 | TEXT_PRESERVE_WHITESPACE |
| 521 | | TEXT_PRESERVE_IMAGES |
| 522 | | TEXT_PRESERVE_LIGATURES |
| 523 | | TEXT_MEDIABOX_CLIP |
| 524 | ) |
| 525 | tp = textpage |
| 526 | if tp is None: |
| 527 | tp = page.get_textpage(clip=clip, flags=flags) |
| 528 | elif getattr(tp, "parent") != page: |
| 529 | raise ValueError("not a textpage of this page") |
| 530 | |
| 531 | blocks = tp.extractBLOCKS() |
| 532 | if textpage is None: |
| 533 | del tp |
| 534 | if sort is True: |
| 535 | blocks.sort(key=lambda b: (b[3], b[0])) |
| 536 | return blocks |
| 537 | |
| 538 | |
| 539 | def get_text_words( |
no test coverage detected
searching dependent graphs…