MCPcopy Create free account
hub / github.com/pymupdf/PyMuPDF / test_2812

Function test_2812

tests/test_tables.py:52–161  ·  view source on GitHub ↗

Ensure table detection and extraction independent from page rotation. Make 4 pages with rotations 0, 90, 180 and 270 degrees respectively. Each page shows the same 8x5 table. We will check that each table is detected and delivers the same content.

()

Source from the content-addressed store, hash-verified

50
51
52def test_2812():
53 """Ensure table detection and extraction independent from page rotation.
54
55 Make 4 pages with rotations 0, 90, 180 and 270 degrees respectively.
56 Each page shows the same 8x5 table.
57 We will check that each table is detected and delivers the same content.
58 """
59 doc = pymupdf.open()
60 # Page 0: rotation 0
61 page = doc.new_page(width=842, height=595)
62 rect = page.rect + (72, 72, -72, -72)
63 cols = 5
64 rows = 8
65 # define the cells, draw the grid and insert unique text in each cell.
66 cells = pymupdf.make_table(rect, rows=rows, cols=cols)
67 for i in range(rows):
68 for j in range(cols):
69 page.draw_rect(cells[i][j])
70 for i in range(rows):
71 for j in range(cols):
72 page.insert_textbox(
73 cells[i][j],
74 f"cell[{i}][{j}]",
75 align=pymupdf.TEXT_ALIGN_CENTER,
76 )
77 page.clean_contents()
78
79 # Page 1: rotation 90 degrees
80 page = doc.new_page()
81 rect = page.rect + (72, 72, -72, -72)
82 cols = 8
83 rows = 5
84 cells = pymupdf.make_table(rect, rows=rows, cols=cols)
85 for i in range(rows):
86 for j in range(cols):
87 page.draw_rect(cells[i][j])
88 for i in range(rows):
89 for j in range(cols):
90 page.insert_textbox(
91 cells[i][j],
92 f"cell[{j}][{rows-i-1}]",
93 rotate=90,
94 align=pymupdf.TEXT_ALIGN_CENTER,
95 )
96 page.set_rotation(90)
97 page.clean_contents()
98
99 # Page 2: rotation 180 degrees
100 page = doc.new_page(width=842, height=595)
101 rect = page.rect + (72, 72, -72, -72)
102 cols = 5
103 rows = 8
104 cells = pymupdf.make_table(rect, rows=rows, cols=cols)
105 for i in range(rows):
106 for j in range(cols):
107 page.draw_rect(cells[i][j])
108 for i in range(rows):
109 for j in range(cols):

Callers

nothing calls this directly

Calls 9

new_pageMethod · 0.80
extractMethod · 0.80
draw_rectMethod · 0.45
insert_textboxMethod · 0.45
clean_contentsMethod · 0.45
set_rotationMethod · 0.45
tobytesMethod · 0.45
closeMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…