Skip to content

Assembly helpers

Utilities for combining existing RTF or DOCX outputs.

rtflite.assemble.assemble_rtf

assemble_rtf(input_files: list[str], output_file: str) -> None

Combine multiple RTF files into a single RTF file.

Parameters:

Name Type Description Default
input_files list[str]

List of paths to RTF files to combine.

required
output_file str

Path to the output RTF file.

required

rtflite.assemble.assemble_docx

assemble_docx(input_files: list[str], output_file: str, landscape: bool | list[bool] = False) -> None

Combine multiple RTF files into a single DOCX file.

Parameters:

Name Type Description Default
input_files list[str]

List of paths to input RTF files.

required
output_file str

Path to the output DOCX file.

required
landscape bool | list[bool]

Whether the output should be landscape. Can be a single bool (applies to all) or a list of bools (one per file). Defaults to False.

False

rtflite.assemble.concatenate_docx

concatenate_docx(input_files: Sequence[str | PathLike[str]], output_file: str | PathLike[str], landscape: bool | Sequence[bool] = False) -> None

Concatenate DOCX files without relying on Word field toggles.

This helper is useful when RTFDocument.write_docx already produced DOCX files and you need to stitch them together into a single document that can be distributed without refreshing fields in Microsoft Word.

Parameters:

Name Type Description Default
input_files Sequence[str | PathLike[str]]

Ordered collection of DOCX file paths to combine. The first document becomes the base; subsequent documents are appended as new sections.

required
output_file str | PathLike[str]

Path to the combined DOCX file.

required
landscape bool | Sequence[bool]

Whether each appended section should be landscape. Accepts a single boolean applied to every section or a list/tuple matching input_files.

False

Raises:

Type Description
ImportError

If python-docx is not installed.

ValueError

If input_files is empty or the landscape list length does not match input_files.

FileNotFoundError

If any input file is missing.