pyrit.prompt_converter.PDFConverter#

class PDFConverter(prompt_template: SeedPrompt | None = None, font_type: str | None = 'Helvetica', font_size: int | None = 12, font_color: tuple | None = (255, 255, 255), page_width: int | None = 210, page_height: int | None = 297, column_width: int | None = 0, row_height: int | None = 10, existing_pdf: Path | None = None, injection_items: List[Dict] | None = None)[source]#

Bases: PromptConverter

Converts a text prompt into a PDF file. Supports various modes: 1. Template-Based Generation: If a SeedPrompt is provided, dynamic data can be injected into the template using the SeedPrompt.render_template_value method, and the resulting content is converted to a PDF. 2. Direct Text-Based Generation: If no template is provided, the raw string prompt is converted directly into a PDF. 3. Modify Existing PDFs (Overlay approach): Enables injecting text into existing PDFs at specified coordinates, merging a new “overlay layer” onto the original PDF.

Parameters:
  • prompt_template (Optional[SeedPrompt], optional) – A SeedPrompt object representing a template.

  • font_type (Optional[str], optional) – Font type for the PDF. Defaults to “Helvetica”.

  • font_size (Optional[int], optional) – Font size for the PDF. Defaults to 12.

  • font_color (Optional[tuple], optional) – Font color for the PDF in RGB format. Defaults to (255, 255, 255).

  • page_width (Optional[int], optional) – Width of the PDF page in mm. Defaults to 210 (A4 width).

  • page_height (Optional[int], optional) – Height of the PDF page in mm. Defaults to 297 (A4 height).

  • column_width (Optional[int], optional) – Width of each column in the PDF. Defaults to 0 (full page width).

  • row_height (Optional[int], optional) – Height of each row in the PDF. Defaults to 10.

  • existing_pdf (Optional[Path], optional) – Path to an existing PDF file. Defaults to None.

  • injection_items (Optional[List[Dict]], optional) – A list of injection items for modifying an existing PDF.

__init__(prompt_template: SeedPrompt | None = None, font_type: str | None = 'Helvetica', font_size: int | None = 12, font_color: tuple | None = (255, 255, 255), page_width: int | None = 210, page_height: int | None = 297, column_width: int | None = 0, row_height: int | None = 10, existing_pdf: Path | None = None, injection_items: List[Dict] | None = None) None[source]#

Methods

__init__([prompt_template, font_type, ...])

convert_async(*, prompt[, input_type])

Converts the given prompt into a PDF.

convert_tokens_async(*, prompt[, ...])

Converts substrings within a prompt that are enclosed by specified start and end tokens.

get_identifier()

input_supported(input_type)

Checks if the input type is supported by the converter

output_supported(output_type)

Checks if the output type is supported by the converter

Attributes

supported_input_types

Returns a list of supported input types for the converter.

supported_output_types

Returns a list of supported output types for the converter.

async convert_async(*, prompt: str, input_type: Literal['text', 'image_path', 'audio_path', 'video_path', 'url', 'error'] = 'text') ConverterResult[source]#

Converts the given prompt into a PDF. If a template is provided, it injects the prompt into the template, otherwise, it generates a simple PDF with the prompt as the content. Further it can modify existing PDFs.

Parameters:
  • prompt (str) – The prompt to be embedded in the PDF.

  • input_type (PromptDataType) – The type of the input data (default: “text”).

Returns:

The result containing the full file path to the generated PDF.

Return type:

ConverterResult

input_supported(input_type: Literal['text', 'image_path', 'audio_path', 'video_path', 'url', 'error']) bool[source]#

Checks if the input type is supported by the converter

Parameters:

input_type – The input type to check

Returns:

True if the input type is supported, False otherwise

Return type:

bool

output_supported(output_type: Literal['text', 'image_path', 'audio_path', 'video_path', 'url', 'error']) bool[source]#

Checks if the output type is supported by the converter

Parameters:

output_type – The output type to check

Returns:

True if the output type is supported, False otherwise

Return type:

bool