MCPcopy
hub / github.com/ArtifexSoftware/pdf2docx / to_table_block

Method to_table_block

pdf2docx/table/TableStructure.py:261–307  ·  view source on GitHub ↗

Convert parsed table structure to ``TableBlock`` instance. Returns: TableBlock: Parsed table block instance.

(self)

Source from the content-addressed store, hash-verified

259
260
261 def to_table_block(self):
262 '''Convert parsed table structure to ``TableBlock`` instance.
263
264 Returns:
265 TableBlock: Parsed table block instance.
266 '''
267 table = TableBlock()
268 for row_structures in self.cells:
269 # row object
270 row = Row()
271 row.height = row_structures[0].bbox.y1-row_structures[0].bbox.y0
272 for cell_structure in row_structures:
273 # if current cell is merged horizontally or vertically, set None.
274 # actually, it will be counted in the top-left cell of the merged range.
275 if cell_structure.is_merged:
276 row.append(Cell())
277 continue
278
279 # cell borders properties
280 top, bottom, left, right = cell_structure.borders
281 w_top = top.width
282 w_right = right.width
283 w_bottom = bottom.width
284 w_left = left.width
285
286 # cell bg-color
287 bg_color = cell_structure.shading.color if cell_structure.shading else None
288
289 # Cell object
290 # Note that cell bbox is calculated under real page CS, so needn't to consider rotation.
291 cell = Cell({
292 'bg_color': bg_color,
293 'border_color': (top.color, right.color, bottom.color, left.color),
294 'border_width': (w_top, w_right, w_bottom, w_left),
295 'merged_cells': cell_structure.merged_cells,
296 }).update_bbox(cell_structure.merged_bbox)
297
298 # add cell to row
299 row.append(cell)
300
301 # add row to table
302 table.append(row)
303
304 # finalize table structure
305 if table: self._finalize_strokes_fills()
306
307 return table
308
309
310 def _finalize_strokes_fills(self):

Callers 2

lattice_tablesMethod · 0.80
stream_tablesMethod · 0.80

Calls 7

appendMethod · 0.95
appendMethod · 0.95
TableBlockClass · 0.90
RowClass · 0.90
CellClass · 0.90
update_bboxMethod · 0.45

Tested by

no test coverage detected