Pagination¶
Advanced pagination features for multi-page documents.
RTFPagination¶
Main pagination controller for handling page breaks and content distribution.
Bases: BaseModel
Core pagination logic and calculations for RTF documents
calculate_available_space()
¶
Calculate available space for content on each page
PageBreakCalculator¶
Calculates optimal page break positions.
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)
¶
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
|
list[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
|
Returns:
Type | Description |
---|---|
list[int]
|
List of row counts for each data row |
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
|
list[float]
|
Column widths in inches |
required |
page_by
|
list[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 |
---|---|
list[tuple[int, int]]
|
List of (start_row, end_row) tuples for each page |
ContentDistributor¶
Distributes content across pages while maintaining formatting.
Bases: BaseModel
Manages content distribution across multiple pages
distribute_content(df, col_widths, page_by=None, new_page=False, pageby_header=True, table_attrs=None, additional_rows_per_page=0, subline_by=None)
¶
Distribute content across multiple pages (r2rtf compatible)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
DataFrame to distribute |
required |
col_widths
|
list[float]
|
Column widths in inches |
required |
page_by
|
list[str] | None
|
Columns to group by |
None
|
new_page
|
bool
|
Force new pages between groups |
False
|
pageby_header
|
bool
|
Repeat headers on new pages |
True
|
table_attrs
|
TableAttributes | None
|
Table attributes for accurate calculations |
None
|
additional_rows_per_page
|
int
|
Additional rows per page (headers, footnotes, sources) |
0
|
subline_by
|
list[str] | None
|
Columns to create subline headers by (forces new_page=True) |
None
|
Returns:
Type | Description |
---|---|
list[dict[str, Any]]
|
List of page information dictionaries |
get_group_headers(df, page_by, start_row)
¶
Get group header information for a page
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
Original DataFrame |
required |
page_by
|
list[str]
|
Grouping columns |
required |
start_row
|
int
|
Starting row for this page |
required |
Returns:
Type | Description |
---|---|
dict[str, Any]
|
Dictionary with group header information |