viking-sudo-rm / rtflib

Python library for writing RTF files.
MIT License
8 stars 4 forks source link

rtflib

A lightweight Python library for exporting RTFs.

I wrote this in middle school more than 10 years ago and have only lightly supported it since. Still, it could get the job done in simple use cases.

If you extend the library, feel free to open a pull request! Here is a reference on RTF syntax which may be helpful for adding features.

Example usage

Hello world example:

from rtflib import Rtf, Line
rtf = Rtf()
rtf.add(Line("hello world"))
rtf.save("rtflib/tests/helloworld.rtf")

The same but in red:

from rtflib import Rtf, Line, Color
rtf = Rtf()
rtf.add(Line("hello world", color=Color(255, 0, 0)))
rtf.save("rtflib/tests/helloworld-red.rtf")

Table example:

from rtflib import Rtf, Table, Row, Line
rtf = Rtf()
rtf.add(Line("here is a table:"))
rtf.add(Table(
    Row(Line("hello"), Line("world")),
    Row(Line("hallo"), Line("Welt")),
))
rtf.save("rtflib/tests/table.rtf")

Running tests

From the root of the repository, run:

pytest

Tests will also be run automatically when a pull request is created.