PDFCanvas

class plutoprint.PDFCanvas(path: str | bytes | PathLike, size: PageSize)[source]

Bases: Canvas

The PDFCanvas class provides an interface for rendering to Adobe PDF files.

__init__(path: str | bytes | PathLike, size: PageSize) None[source]

Initializes a new PDFCanvas with the specified file path and page size.

Parameters:
  • path – The file path where the PDF document will be written.

  • size – The size of the PDF page.

classmethod create_for_stream(stream: BinaryIO, size: PageSize) PDFCanvas[source]

Creates a new PDFCanvas for the given writable binary stream and page size.

Parameters:
  • stream – A writable binary stream where the PDF document will be written.

  • size – The size of the PDF page.

Returns:

A new instance of PDFCanvas.

set_metadata(metadata: PDFMetadata, value: str) None[source]

Sets the metadata of the PDF document.

The PDF_METADATA_CREATION_DATE and PDF_METADATA_MODIFICATION_DATE values must be in ISO-8601 format: YYYY-MM-DDThh:mm:ss. An optional timezone of the form “[+/-]hh:mm” or “Z” for UTC time can be appended. All other metadata values can be any string.

Parameters:
  • metadata – The type of metadata to set.

  • value – The value of the metadata.

set_size(size: PageSize) None[source]

Sets the size of the PDF page.

This function should only be called before any drawing operations have been performed on the current page. The simplest way to do this is to call this function immediately after creating the canvas or immediately after completing a immediately after completing a page with show_page().

Parameters:

size – The size of the PDF page.

show_page() None[source]

Emits the current page and starts a new page.