pdf2docx.table.Border module#

Module to determine stream table borders.

Though no exact borders exist for stream table, it’s better to simplify table structure by aligning borders as more as possible. Taking vertical borders for example, it can be moved in a valid range in horizontal direction, but restricted by top and bottom borders in vertical direction. It’s also true for horizontal borders.

Accordingly, introduce Border object, which has the following attributes:

  • Valid range, e.g. (100, 250);

  • Boundary borders, e.g. (top_border, bottom_border) for v-border, or (left_border, right_border) for h-border.

The target is to finalize the position in valid range, e.g. x=125 for v-border with valid range (120, 250). Then it’s y-direction is determined by its boundary borders, where the y-coordinates are finalized in same logic. Finally, this border is fixed since both x- and y- directions are determined.

Note

Consider horizontal and vertical borders only.

class pdf2docx.table.Border.Border(border_type='hi', border_range: Optional[tuple] = None, borders: Optional[tuple] = None, reference: bool = False)#

Bases: object

Border for stream table.

property centerline#

Center line of this border.

finalize_by_stroke(stroke: Stroke)#

Finalize border with specified stroke shape, which is generally a showing border-like shape.

Args:

stroke (Stroke): Target stroke to finalize this border.

Note

  • The boundary borders may also be affected by this stroke shape.

  • The border-like stroke may be an underline or strike-through.

finalize_by_value(value: float)#

Finalize border with given position.

Args:

value (float): Target position.

get_boundary_borders()#

Get boundary borders.

Returns:

tuple: (lower b-border, upper b-border)

property is_bottom#
property is_horizontal#
property is_top#
is_valid(value: float)#

Whether the given position locates in the valid border range.

Args:

value (float): Target position.

Returns:

bool: Valid position or not.

property is_vertical#
set_border_range(border_range: Optional[tuple] = None)#

Set border valid ranges.

Args:

border_range (tuple, optional): Lower/upper range to set. Defaults to None.

Returns:

Border: self

set_boundary_borders(borders: Optional[tuple] = None)#

Set boundary borders.

Args:

borders (tuple, optional): Lower/upper boundary borders to set. Defaults to None.

Returns:

Border: self

to_stroke()#

Convert to border stroke.

property value#

Finalized position, e.g. y-coordinate of horizontal border.

Average value if not finalized, but close to the table side for top and bottom boundary borders.

class pdf2docx.table.Border.Borders(instances: Optional[list] = None, parent=None)#

Bases: BaseCollection

Collection of Border instances.

finalize(strokes: Shapes, fills: Shapes)#

Finalize the position of all borders.

Args:

strokes (Shapes): A group of explicit border strokes. fills (Shapes): A group of explicit cell shadings.

Note

A border is finalized in priority below:

  • Follow explicit stroke/border.

  • Follow explicit fill/shading.

  • Align h-borders or v-borders as more as possible to simplify the table structure.