pyhanko.pdf_utils.text module

Utilities related to text rendering & layout.

class pyhanko.pdf_utils.text.TextStyle(font: pyhanko.pdf_utils.font.api.FontEngineFactory = <factory>, font_size: int = 10, leading: Optional[int] = None)

Bases: pyhanko.pdf_utils.config_utils.ConfigurableMixin

Container for basic test styling settings.

font: pyhanko.pdf_utils.font.api.FontEngineFactory

The FontEngineFactory to be used for this text style. Defaults to Courier (as a non-embedded standard font).

font_size: int = 10

Font size to be used.

leading: int = None

Text leading. If None, the font_size parameter is used instead.

classmethod process_entries(config_dict)

Hook method that can modify the configuration dictionary to overwrite or tweak some of their values (e.g. to convert string parameters into more complex Python objects)

Subclasses that override this method should call super().process_entries(), and leave keys that they do not recognise untouched.

Parameters

config_dict – A dictionary containing configuration values.

Raises

ConfigurationError – when there is a problem processing a relevant entry.

class pyhanko.pdf_utils.text.TextBoxStyle(font: pyhanko.pdf_utils.font.api.FontEngineFactory = <factory>, font_size: int = 10, leading: Optional[int] = None, border_width: int = 0, box_layout_rule: Optional[pyhanko.pdf_utils.layout.SimpleBoxLayoutRule] = None, vertical_text: bool = False)

Bases: pyhanko.pdf_utils.text.TextStyle

Extension of TextStyle for use in text boxes.

border_width: int = 0

Border width, if applicable.

box_layout_rule: pyhanko.pdf_utils.layout.SimpleBoxLayoutRule = None

Layout rule to nest the text within its containing box.

Warning

This only affects the position of the text object, not the alignment of the text within.

vertical_text: bool = False

Switch layout code to vertical mode instead of horizontal mode.

class pyhanko.pdf_utils.text.TextBox(style: pyhanko.pdf_utils.text.TextBoxStyle, writer, resources: Optional[pyhanko.pdf_utils.content.PdfResources] = None, box: Optional[pyhanko.pdf_utils.layout.BoxConstraints] = None, font_name='F1')

Bases: pyhanko.pdf_utils.content.PdfContent

Implementation of a text box that implements the PdfContent interface.

Note

Text boxes currently don’t offer automatic word wrapping.

put_string_line(txt)
property content_lines
Returns

Text content of the text box, broken up into lines.

property content
Returns

The actual text content of the text box. This is a modifiable property.

In textboxes that don’t have a fixed size, setting this property can cause the text box to be resized.

property leading
Returns

The effective leading value, i.e. the leading attribute of the associated TextBoxStyle, or font_size if not specified.

render()

Compile the content to graphics operators.