PDF Report#

class PDFReport(orientation='L', unit='mm', format='A4', date_format='%B %d %Y')[source]#

Bases: FPDF

The PDFReport class extends FPDF to create a PDF report from an Excel file containing patch data.

It supports custom headers, footers, font styles, and an optional branding logo based on the UI configuration.

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”.

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]