PDF ReportΒΆ

class PDFReport(orientation='L', unit='mm', format='A4', date_format='%B %d %Y', ui_config: dict | None = None)[source]ΒΆ

Bases: FPDF

Extends FPDF to produce a PDF patch report from a styled DataFrame.

The ui_config dict drives header/footer text, font selection, branding logo, and header color. When omitted, UIDefaults is used (no plist read, no I/O). The CLI passes UIConfigManager.config (a plist-backed dict); library callers pass a dict they constructed themselves or read from elsewhere.

Parameters:
  • orientation (str) – Orientation of the PDF, default is β€œL” (landscape).

  • unit (str) – Unit of measurement, default is β€œmm”.

  • format (str) – Page format, default is β€œA4”.

  • date_format (str) – Date format string for the PDF report header, default is β€œ%B %d %Y”.

  • ui_config (dict | None) – Dict of UI settings (header text, footer, font paths, logo, header color). Defaults to UIDefaults values.

static get_image_ratio(image_path: str) float[source]ΒΆ

Gets the aspect ratio of the logo provided.

Parameters:

image_path (str) – Path to the image file

Returns:

The width-to-height ratio of the image.

Return type:

float

static trim_transparency(image_path: str) str[source]ΒΆ

Trims transparent padding from the logo and returns the path to a temporary file.

Parameters:

image_path (str) – Path to the input image file.

Returns:

Path to the trimmed image.

Return type:

str

header()[source]ΒΆ

Creates the header section for each page of the PDF report with an optional logo.

The header includes the configured header text and the current date formatted according to self.date_format. On subsequent pages, the table header is also added.

add_table_header()[source]ΒΆ

Adds the table header to the PDF report.

This method is called on pages after the first to add column headers for the data table in the PDF report. The headers and their widths are defined by self.table_headers and self.column_widths.

footer()[source]ΒΆ

Creates the footer section for each page of the PDF report.

The footer includes the configured footer text and the current page number. The footer text is styled with a smaller font and a light gray color.

calculate_column_widths(data: DataFrame) list[float][source]ΒΆ

Calculates column widths based on the longer of the header length or the longest content in each column, ensuring they fit within the page width.

Parameters:

data (pandas.DataFrame) – DataFrame containing dataset to be included in PDF.

Returns:

A list of column widths proportional to header lengths.

Return type:

list [float]