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: pymupdf.Page,
clip: rect_like = None,
flags: OptInt = None,
textpage: pymupdf.TextPage = None,
sort: bool = False,
)
| 50 | |
| 51 | |
| 52 | def get_text_blocks( |
| 53 | page: pymupdf.Page, |
| 54 | clip: rect_like = None, |
| 55 | flags: OptInt = None, |
| 56 | textpage: pymupdf.TextPage = None, |
| 57 | sort: bool = False, |
| 58 | ) -> list: |
| 59 | """Return the text blocks on a page. |
| 60 | |
| 61 | Notes: |
| 62 | Lines in a block are concatenated with line breaks. |
| 63 | Args: |
| 64 | flags: (int) control the amount of data parsed into the textpage. |
| 65 | Returns: |
| 66 | A list of the blocks. Each item contains the containing rectangle |
| 67 | coordinates, text lines, running block number and block type. |
| 68 | """ |
| 69 | pymupdf.CheckParent(page) |
| 70 | if flags is None: |
| 71 | flags = pymupdf.TEXTFLAGS_BLOCKS |
| 72 | tp = textpage |
| 73 | if tp is None: |
| 74 | tp = page.get_textpage(clip=clip, flags=flags) |
| 75 | elif getattr(tp, "parent") != page: |
| 76 | raise ValueError("not a textpage of this page") |
| 77 | |
| 78 | blocks = tp.extractBLOCKS() |
| 79 | if textpage is None: |
| 80 | del tp |
| 81 | if sort: |
| 82 | blocks.sort(key=lambda b: (b[3], b[0])) |
| 83 | return blocks |
| 84 | |
| 85 | |
| 86 | def get_text_words( |
no test coverage detected
searching dependent graphs…