pdftools_toolbox.pdf.content.text_generator

Classes

TextGenerator(text, font, font_size, location)

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:
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 fill: Paint | None
property stroke: Stroke | None
property font: Font
property font_size: float
property character_spacing: float
property word_spacing: float
property horizontal_scaling: float
property leading: float
property rise: float