pyhanko.pdf_utils.text module¶
Utilities related to text rendering & layout.
-
class
pyhanko.pdf_utils.text.
TextStyle
(font: Union[pyhanko.pdf_utils.font.FontEngine, Callable[[], pyhanko.pdf_utils.font.FontEngine]] = <factory>, font_size: int = 10, leading: Optional[int] = None)¶ Bases:
pyhanko.pdf_utils.config_utils.ConfigurableMixin
Container for basic test styling settings.
-
font
: Union[pyhanko.pdf_utils.font.FontEngine, Callable[], pyhanko.pdf_utils.font.FontEngine]]¶ The
FontEngine
to be used for this text style. Defaults to Courier (as a non-embedded standard font).Caution
Not all
FontEngine
implementations are reusable and/or stateless! When reusability is a requirement, passing a no-argument callable that producesFontEngine
objects of the appropriate type might help (seeGlyphAccumulatorFactory
).
-
font_size
: int = 10¶ Font size to be used.
-
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: Union[pyhanko.pdf_utils.font.FontEngine, Callable[[], pyhanko.pdf_utils.font.FontEngine]] = <factory>, font_size: int = 10, leading: Optional[int] = None, text_sep: int = 10, border_width: int = 0, vertical_center: bool = True)¶ Bases:
pyhanko.pdf_utils.text.TextStyle
Extension of
TextStyle
for use in text boxes.-
text_sep
: int = 10¶ Separation of text from the box’s border, in user units.
-
border_width
: int = 0¶ Border width, if applicable.
-
vertical_center
: bool = True¶ Attempt to vertically center text if the box’s height is fixed.
-
-
class
pyhanko.pdf_utils.text.
TextBox
(style: pyhanko.pdf_utils.text.TextBoxStyle, resources: Optional[pyhanko.pdf_utils.content.PdfResources] = None, box: Optional[pyhanko.pdf_utils.layout.BoxConstraints] = None, writer=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.
-
wrap_string
(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 associatedTextBoxStyle
, orfont_size
if not specified.
-
get_text_height
()¶ - Returns
The text height in user units.
-
text_x
()¶ - Returns
The x-position where the text will be painted.
-
text_y
()¶ - Returns
The y-position where the text will be painted.
-
render
()¶ Compile the content to graphics operators.
-