Skip to content

Pagination

Metadata-driven pagination utilities and strategies used by the unified encoder.

RTFPagination

Core pagination settings used to calculate available space on each page.

Bases: BaseModel

Core pagination logic and calculations for RTF documents

calculate_available_space()

Calculate available space for content on each page

PageBreakCalculator

Calculates row metadata, page assignments, and optimal break points.

Bases: BaseModel

Calculates where page breaks should occur based on content and constraints

calculate_content_rows(df, col_widths, table_attrs=None, font_size=9, spanning_columns=None)

Calculate how many rows each content row will occupy when rendered

Parameters:

Name Type Description Default
df DataFrame

DataFrame containing the content

required
col_widths Sequence[float]

Width of each column in inches

required
table_attrs TableAttributes | None

Table attributes containing cell height and font size info

None
font_size float

Default font size in points

9
spanning_columns Sequence[str] | None

Columns that should be treated as spanning the full width

None

Returns:

Type Description
Sequence[int]

List of row counts for each data row

calculate_row_metadata(df, col_widths, page_by=None, subline_by=None, table_attrs=None, removed_column_indices=None, font_size=9, additional_rows_per_page=0, new_page=False)

Generate complete row metadata for pagination.

find_page_breaks(df, col_widths, page_by=None, new_page=False, table_attrs=None, additional_rows_per_page=0)

Find optimal page break positions (r2rtf compatible)

Parameters:

Name Type Description Default
df DataFrame

DataFrame to paginate

required
col_widths Sequence[float]

Column widths in inches

required
page_by Sequence[str] | None

Columns to group by for page breaks

None
new_page bool

Whether to force new pages between groups

False
table_attrs TableAttributes | None

Table attributes for accurate row calculation

None
additional_rows_per_page int

Additional rows per page (headers, footnotes, sources)

0

Returns:

Type Description
Sequence[tuple[int, int]]

List of (start_row, end_row) tuples for each page

Pagination contexts and registry

Bases: BaseModel

Context passed to the strategy to perform pagination.

Bases: BaseModel

Holds all data and metadata required to render a single page.

Registry for pagination strategies.

get(name) classmethod

Get a strategy by name.

list_strategies() classmethod

List all registered strategies.

register(name, strategy_cls) classmethod

Register a new strategy.

Bases: ABC

Abstract base class for pagination strategies.

paginate(context) abstractmethod

Split the document into pages based on the strategy.

Built-in strategies

Bases: PaginationStrategy

Default pagination strategy based on row counts and page size.

Bases: PaginationStrategy

Pagination strategy that respects grouping columns (page_by).

Bases: PageByStrategy

Pagination strategy for subline_by (forces new pages and special headers).

Page feature processing

Processes page features like borders, headers, and footers for each page.

process(document, page)

Process a single page to apply all feature-specific logic.