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.
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")
From the root of the repository, run:
pytest
Tests will also be run automatically when a pull request is created.