PDF Report#

Model inherits from FPDF.

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

Handles the generation of PDF reports from Excel files.

The PDFReport class extends FPDF to create a PDF report from an Excel file containing patch data. It supports custom headers, footers, and font styles based on the UI configuration.

Initializes the PDFReport with the provided parameters and UIConfigManager.

Parameters:
  • ui_config (UIConfigManager) – An instance of UIConfigManager for managing UI configuration.

  • 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]

export_excel_to_pdf(excel_file: str | Path, date_format: str = '%B %d %Y') None[source]#

Creates a PDF report from an Excel file containing patch data.

This method reads an Excel file, extracts the data, and populates it into a PDF report using the defined headers and column widths. The PDF is then saved to the same directory as the Excel file.

Parameters:
  • excel_file (Union[str, Path]) – Path to the Excel file to convert to PDF.

  • date_format (str) – The date format string for the PDF report header.

Return type:

None