Page format¶
This article demonstrates how to control component placement in multi-page documents using rtflite.
When generating multi-page RTF documents, you may want to control where titles,
footnotes, and sources appear. The RTFPage
class provides three parameters
to control this behavior:
page_title
: Controls where titles appear ("first", "last", "all")page_footnote
: Controls where footnotes appear ("first", "last", "all")page_source
: Controls where sources appear ("first", "last", "all")
Default behavior¶
Default settings
- Titles appear on all pages (
page_title="all"
) - Footnotes appear on the last page only (
page_footnote="last"
) - Sources appear on the last page only (
page_source="last"
)
Examples¶
Basic setup¶
from importlib.resources import files
import polars as pl
from rtflite import RTFDocument, RTFFootnote, RTFPage, RTFSource, RTFTitle
# Load the adverse events dataset
data_path = files("rtflite.data").joinpath("adae.parquet")
df = pl.read_parquet(data_path).head(30)
Example 1: default behavior¶
# Default: title on all pages, footnote and source on last page
doc_default = RTFDocument(
df=df.select(
["USUBJID", "TRTA", "AEDECOD", "AESEV", "AESER", "AEREL"]
), # Select key columns
rtf_page=RTFPage(nrow=15), # Force pagination with 15 rows per page
rtf_title=RTFTitle(text="Adverse Events Summary by Treatment"),
rtf_footnote=RTFFootnote(
text="Abbreviations: USUBJID=Subject ID, TRTA=Treatment, AEDECOD=Adverse Event, AESEV=Severity, AESER=Serious, AEREL=Related"
),
rtf_source=RTFSource(text="Source: ADAE Dataset from Clinical Trial Database"),
)
# Generate RTF and save to file
doc_default.write_rtf("format-page-default.rtf")
Example 2: title on first page only¶
# Title on first page only, footnote and source on last page
doc_title_first = RTFDocument(
df=df.select(["USUBJID", "TRTA", "AEDECOD", "AESEV", "AESER", "AEREL"]),
rtf_page=RTFPage(
nrow=15,
page_title="first", # Title on first page only
page_footnote="last", # Footnote on last page (default)
page_source="last", # Source on last page (default)
),
rtf_title=RTFTitle(text="Adverse Events Summary by Treatment"),
rtf_footnote=RTFFootnote(
text="Abbreviations: USUBJID=Subject ID, TRTA=Treatment, AEDECOD=Adverse Event, AESEV=Severity, AESER=Serious, AEREL=Related"
),
rtf_source=RTFSource(text="Source: ADAE Dataset from Clinical Trial Database"),
)
# Save to RTF file
doc_title_first.write_rtf("format-page-title-first.rtf")
Example 3: footnote on first page¶
# Title on first page (default), footnote on first page, source on last page
doc_footnote_first = RTFDocument(
df=df.select(["USUBJID", "TRTA", "AEDECOD", "AESEV", "AESER", "AEREL"]),
rtf_page=RTFPage(
nrow=15,
page_title="first", # Title on first page
page_footnote="first", # Footnote on first page
page_source="last", # Source on last page (default)
),
rtf_title=RTFTitle(text="Adverse Events Summary by Treatment"),
rtf_footnote=RTFFootnote(
text="Abbreviations: USUBJID=Subject ID, TRTA=Treatment, AEDECOD=Adverse Event, AESEV=Severity, AESER=Serious, AEREL=Related"
),
rtf_source=RTFSource(text="Source: ADAE Dataset from Clinical Trial Database"),
)
# Save to RTF file
doc_footnote_first.write_rtf("format-page-footnote-first.rtf")
Example 4: all components on all pages¶
# All components on all pages
doc_all_pages = RTFDocument(
df=df.select(["USUBJID", "TRTA", "AEDECOD", "AESEV", "AESER", "AEREL"]),
rtf_page=RTFPage(
nrow=15,
page_title="all", # Title on all pages
page_footnote="all", # Footnote on all pages
page_source="all", # Source on all pages
),
rtf_title=RTFTitle(text="Adverse Events Summary by Treatment"),
rtf_footnote=RTFFootnote(
text="Abbreviations: USUBJID=Subject ID, TRTA=Treatment, AEDECOD=Adverse Event, AESEV=Severity, AESER=Serious, AEREL=Related"
),
rtf_source=RTFSource(text="Source: ADAE Dataset from Clinical Trial Database"),
)
# Save to RTF file
doc_all_pages.write_rtf("format-page-all-pages.rtf")
Example 5: custom combination¶
# Custom combination: title everywhere, footnote on first page, source on last page
doc_custom = RTFDocument(
df=df.select(["USUBJID", "TRTA", "AEDECOD", "AESEV", "AESER", "AEREL"]),
rtf_page=RTFPage(
nrow=15,
page_title="all", # Title on all pages
page_footnote="first", # Footnote on first page only
page_source="last", # Source on last page only
),
rtf_title=RTFTitle(text="Adverse Events Summary by Treatment"),
rtf_footnote=RTFFootnote(
text="Abbreviations: USUBJID=Subject ID, TRTA=Treatment, AEDECOD=Adverse Event, AESEV=Severity, AESER=Serious, AEREL=Related"
),
rtf_source=RTFSource(text="Source: ADAE Dataset from Clinical Trial Database"),
)
# Save to RTF file
doc_custom.write_rtf("format-page-custom.rtf")