pdftools_toolbox.pdf.content.text_generator
Classes
|
- class pdftools_toolbox.pdf.content.text_generator.TextGenerator(text: Text, font: Font, font_size: float, location: Point | None)[source]
Bases:
_NativeObject
- __init__(text: Text, font: Font, font_size: float, location: Point | None)[source]
Create a new text generator for appending text to a text content object.
All parameters that cannot be set in the constructor are set to default values:
Rendering: fill text with black paint
CharacterSpacing: 0
WordSpacing: 0
HorizontalScaling: 1
Leading: 1.2 times the fontSize (The font’s
pdftools_toolbox.pdf.content.font.Font.leading
is not used.)Rise: 0
Stroke: None
IntersectClipping: False
- Parameters:
text (pdftools_toolbox.pdf.content.text.Text) – the text object
font (pdftools_toolbox.pdf.content.font.Font) – the initial font
fontSize (float) – the initial font size and leading
location (Optional[pdftools_toolbox.geometry.real.point.Point]) – the initial position. If position is None, the default position [0, 0] is used.
- Raises:
ValueError – if the document associated with the text object has already been closed
ValueError – if the text and font objects are associated with different documents
ValueError – if the document associated with the font object has already been closed
ValueError – if the font has been obtained from
pdftools_toolbox.pdf.content.text_fragment.TextFragment.font
- get_width(text: str | None) float [source]
Get the width of a text string.
The width of a text string as if it would be shown with the current settings.
- Parameters:
text (Optional[str]) – the text fragment
- Returns:
the width of the text
- Return type:
float
- Raises:
StateError – if the object has already been closed
StateError – if the underlying text object has already been closed
ValueError – if the text argument is None
- show(text: str | None) None [source]
Show a text string.
The text is shown using the current settings.
- Parameters:
text (Optional[str]) – the text to be shown
- Raises:
StateError – if the object has already been closed
StateError – if the underlying text object has already been closed
ValueError – if the text argument is None
- show_line(text: str | None) None [source]
Show a text string and go to the next line.
- Parameters:
text (Optional[str]) – the text to be shown
- Raises:
StateError – if the object has already been closed
StateError – if the underlying text object has already been closed
ValueError – if the text argument is None
- move_to(target: Point) None [source]
Move the current position.
This also also sets the beginning of the current line to the specified position, which will affect the
pdftools_toolbox.pdf.content.text_generator.TextGenerator.show_line()
method.- Parameters:
target (pdftools_toolbox.geometry.real.point.Point) – the target position
- Raises:
StateError – if the object has already been closed
StateError – if the underlying text object has already been closed
- property font_size: float
- property character_spacing: float
- property word_spacing: float
- property horizontal_scaling: float
- property leading: float
- property rise: float