MCPcopy Index your code
hub / github.com/pymupdf/PyMuPDF / extract

Method extract

src/table.py:1559–1595  ·  view source on GitHub ↗
(self, **kwargs)

Source from the content-addressed store, hash-verified

1557 return max([len(r.cells) for r in self.rows])
1558
1559 def extract(self, **kwargs) -> list:
1560 chars = CHARS
1561 table_arr = []
1562
1563 def char_in_bbox(char, bbox) -> bool:
1564 v_mid = (char["top"] + char["bottom"]) / 2
1565 h_mid = (char["x0"] + char["x1"]) / 2
1566 x0, top, x1, bottom = bbox
1567 return bool(
1568 (h_mid >= x0) and (h_mid < x1) and (v_mid >= top) and (v_mid < bottom)
1569 )
1570
1571 for row in self.rows:
1572 arr = []
1573 row_chars = [char for char in chars if char_in_bbox(char, row.bbox)]
1574
1575 for cell in row.cells:
1576 if cell is None:
1577 cell_text = None
1578 else:
1579 cell_chars = [
1580 char for char in row_chars if char_in_bbox(char, cell)
1581 ]
1582
1583 if len(cell_chars):
1584 kwargs["x_shift"] = cell[0]
1585 kwargs["y_shift"] = cell[1]
1586 if "layout" in kwargs:
1587 kwargs["layout_width"] = cell[2] - cell[0]
1588 kwargs["layout_height"] = cell[3] - cell[1]
1589 cell_text = extract_text(cell_chars, **kwargs)
1590 else:
1591 cell_text = ""
1592 arr.append(cell_text)
1593 table_arr.append(arr)
1594
1595 return table_arr
1596
1597 def to_markdown(self, clean=False, fill_empty=True):
1598 """Output table content as a string in Github-markdown format.

Callers 8

to_pandasMethod · 0.95
_get_headerMethod · 0.95
test_table1Function · 0.80
test_2812Function · 0.80
test_2979Function · 0.80
test_3148Function · 0.80
test_boxes_paramFunction · 0.80
test_4017Function · 0.80

Calls 2

extract_textFunction · 0.85
appendMethod · 0.45

Tested by 6

test_table1Function · 0.64
test_2812Function · 0.64
test_2979Function · 0.64
test_3148Function · 0.64
test_boxes_paramFunction · 0.64
test_4017Function · 0.64