PyRTF3

0.47.5 · active · verified Fri Apr 17

PyRTF3 is a fork of the original PyRTF library, providing a Pythonic way to generate Rich Text Format (RTF) documents. It allows users to programmatically create complex RTF files including text, paragraphs, sections, tables, lists, and styling. The current version is 0.47.5, with releases occurring periodically to address issues and maintain compatibility.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart creates a basic RTF document with two paragraphs of text and saves it to a file named 'simple_pyrtf3_document.rtf'. It demonstrates the core Document, Section, Paragraph, and Text objects.

import os
from pyrtf.document import Document, Section, Paragraph, Text

def create_simple_rtf():
    doc = Document()
    section = Section()
    doc.append(section)

    section.append(Paragraph(Text('Hello, PyRTF3!')))
    section.append(Paragraph(Text('This is a simple RTF document generated with Python.')))

    output_filename = 'simple_pyrtf3_document.rtf'
    with open(output_filename, 'wb') as f:
        doc.write(f)

    print(f"RTF document '{output_filename}' created successfully.")

if __name__ == '__main__':
    create_simple_rtf()

view raw JSON →