pyhanko.pdf_utils.layout module

Layout utilities (to be expanded)

exception pyhanko.pdf_utils.layout.BoxSpecificationError

Bases: ValueError

Raised when a box constraint is over/underspecified.

class pyhanko.pdf_utils.layout.BoxConstraints(width=None, height=None, aspect_ratio: Optional[fractions.Fraction] = None)

Bases: object

Represents a box of potentially variable width and height. Among other uses, this can be leveraged to produce a variably sized box with a fixed aspect ratio.

If width/height are not defined yet, they can be set by assigning to the width and height attributes.

property width
Returns

The width of the box.

Raises

BoxSpecificationError – if the box’s width could not be determined.

property width_defined
Returns

True if the box currently has a well-defined width, False otherwise.

property height
Returns

The height of the box.

Raises

BoxSpecificationError – if the box’s height could not be determined.

property height_defined
Returns

True if the box currently has a well-defined height, False otherwise.

property aspect_ratio
Returns

The aspect ratio of the box.

Raises

BoxSpecificationError – if the box’s aspect ratio could not be determined.

property aspect_ratio_defined
Returns

True if the box currently has a well-defined aspect ratio, False otherwise.