Skip to content

Page Layout Components

Components for defining page structure, headers, footers, and overall document layout.

RTFPage

Defines page dimensions, margins, and layout settings.

Bases: BaseModel

Configure RTF page layout and pagination settings.

The RTFPage component controls page dimensions, margins, orientation, and pagination behavior including rows per page and border styles for first/last rows across page boundaries.

Examples:

Basic portrait page with custom margins:

page = RTFPage(
    orientation="portrait",
    margin=[1.0, 1.0, 1.5, 1.0, 1.5, 1.0]  # left, right, top, bottom, header, footer
)

Landscape layout for wide tables:

page = RTFPage(
    orientation="landscape",
    nrow=30,  # Fewer rows due to landscape
    border_first="double",  # Double border on first row
    border_last="single"    # Single border on last row
)

Attributes:

Name Type Description
nrow int | None

Total number of rows per page including ALL components: - Column headers (if displayed) - Data rows - Footnotes (if present) - Source lines (if present) This is NOT just data rows - it's the complete row budget.

border_first str | None

Border style for the first row of the table. Defaults to "double" for emphasis.

border_last str | None

Border style for the last row of the table. Defaults to "double" for closure.

Note

The nrow parameter represents the total row capacity of a page, not just data rows. Plan accordingly when setting this value.

RTFPageHeader

Creates headers that appear at the top of pages.

Bases: RTFTextComponent

RTF page header component for document headers.

The RTFPageHeader appears at the top of every page, typically used for page numbering, document titles, or study identifiers. Right-aligned by default with automatic page numbering.

Examples:

Default page numbering:

header = RTFPageHeader()  # Shows "Page X of Y"

Custom header text:

header = RTFPageHeader(
    text="Protocol ABC-123 | Confidential",
    text_justification=["c"]  # Center align
)

Header with page number:

header = RTFPageHeader(
    text="Study Report - Page \\chpgn",  # Current page number
    text_format=["b"],  # Bold
    text_font_size=[10]
)

Note
  • Default text is "Page \chpgn of {\field{\*\fldinst NUMPAGES }}"
  • Text conversion is disabled by default to preserve RTF field codes
  • Right-aligned by default

RTFPageFooter

Creates footers that appear at the bottom of pages.

Bases: RTFTextComponent

RTF page footer component for document footers.

The RTFPageFooter appears at the bottom of every page, typically used for confidentiality notices, timestamps, or file paths. Center-aligned by default.

Examples:

Simple footer:

footer = RTFPageFooter(
    text="Company Confidential"
)

Multi-line footer:

footer = RTFPageFooter(
    text=[
        "Proprietary and Confidential",
        "Do Not Distribute"
    ],
    text_font_size=[8, 8]
)

Footer with timestamp:

footer = RTFPageFooter(
    text="Generated: 2024-01-15 14:30:00 | program.py",
    text_justification=["l"],  # Left align
    text_font_size=[8]
)

Note
  • Center-aligned by default
  • Text conversion is disabled by default to preserve special characters
  • Appears on every page of the document

RTFTitle

Defines document and table titles.

Bases: RTFTextComponent

RTF title component with center-aligned text and LaTeX conversion enabled.

The RTFTitle component displays centered title text at the top of the document or table. It supports multiple title lines and LaTeX-style text conversion for mathematical symbols and formatting.

Examples:

Single line title:

title = RTFTitle(text="Adverse Events Summary")

Multi-line title with formatting:

title = RTFTitle(
    text=["Clinical Study Report", "Safety Analysis Set"],
    text_format=["b", ""]  # First line bold, second normal
)

Title with LaTeX symbols:

title = RTFTitle(
    text="Efficacy Analysis (\\alpha = 0.05)"
)
# Renders as: Efficacy Analysis (alpha = 0.05) with Greek alpha symbol

Note

Text conversion is enabled by default for titles, converting: - LaTeX symbols (e.g., \alpha to Greek alpha, \beta to Greek beta) - Subscripts (e.g., x_1 to x with subscript 1) - Other mathematical notation

RTFFootnote

Creates footnotes for tables and documents.

Bases: RTFTableTextComponent

RTF footnote component for explanatory notes and citations.

The RTFFootnote component displays footnote text at the bottom of tables. Supports multiple footnote lines and can be rendered as a table (with borders) or plain text. Text conversion is enabled by default.

Examples:

Single footnote:

footnote = RTFFootnote(
    text="CI = Confidence Interval; N = Number of subjects"
)

Multiple footnotes:

footnote = RTFFootnote(
    text=[
        "* p-value from ANCOVA model",
        "** Missing values were imputed using LOCF",
        "*** Baseline is defined as last value before first dose"
    ]
)

Footnote without table borders:

footnote = RTFFootnote(
    text="Data cutoff date: 2023-12-31",
    as_table=False  # No borders around footnote
)

Note
  • Multiple footnote lines are joined with \line separator
  • Text conversion is enabled by default (LaTeX symbols supported)
  • Default rendering includes table borders (as_table=True)

RTFSource

Adds source information to documents.

Bases: RTFTableTextComponent

RTF source component for data source citations.

The RTFSource component displays source information at the very bottom of the document. Typically used for dataset names, program references, or generation timestamps. Rendered as plain text without borders by default.

Examples:

Simple source citation:

source = RTFSource(
    text="Source: ADAE dataset, generated 2024-01-15"
)

Multiple source lines:

source = RTFSource(
    text=[
        "Dataset: ADAE version 3.0",
        "Program: ae_summary.py",
        "Generated: 2024-01-15 14:30:00"
    ]
)

Source with table borders:

source = RTFSource(
    text="Database lock: 2023-12-31",
    as_table=True,  # Add borders around source
    text_justification=[["l"]]  # Left align instead of center
)

Note
  • Center-aligned by default
  • Rendered without borders by default (as_table=False)
  • Text conversion is enabled by default