Skip to main content

A simple library to convert rtf to text

Project description

striprtf

Build status

Purpose

This is a library to convert Rich Text Format (RTF) files to plain text files. A lot of medical documents are written in RTF format which is not ideal for parsing and further processing. This library converts it to plain old text.

How to use it

from striprtf.striprtf import rtf_to_text
rtf = "some rtf encoded string"
text = rtf_to_text(rtf)
print(text)

If you want to use a different encoding than cp1252 you can pass it via the encoding parameter. This is only taken into account if no explicit codepage has been set.

from striprtf.striprtf import rtf_to_text
rtf = "some rtf encoded string in latin1"
text = rtf_to_text(rtf, encoding="latin-1")
print(text)

Sometimes UnicodeDecodingErrors can happen because of various reasons. In this case you can try to relax the encoding process like this:

from striprtf.striprtf import rtf_to_text
rtf = "some rtf encoded string"
text = rtf_to_text(rtf, errors="ignore")
print(text)

Online version

If you don't want to install or just try it out there is an online version available.

PostgreSQL

There is also a PostgreSQL version available from Raffael Mancini.

History

Pyth was not working for the rtf files I had. The next best thing was this gist: https://gist.github.com/gilsondev/7c1d2d753ddb522e7bc22511cfb08676

~~Very few additions where made, e.g. better formatting of tables. ~~

In the meantime some encodings bugs have been fixed. :-)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

striprtf-0.0.31.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

striprtf-0.0.31-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file striprtf-0.0.31.tar.gz.

File metadata

  • Download URL: striprtf-0.0.31.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for striprtf-0.0.31.tar.gz
Algorithm Hash digest
SHA256 ce4b6403427d7d5cda95fdb61365432225f6fbe5ea6797e1357f4045d351ba2d
MD5 6bd70da448aa70ebc34326c3c7879363
BLAKE2b-256 4fbe3208376f236433ac627ee33129cfc6a1cea3ea2efea6ac7f11e4b6651f15

See more details on using hashes here.

File details

Details for the file striprtf-0.0.31-py3-none-any.whl.

File metadata

  • Download URL: striprtf-0.0.31-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for striprtf-0.0.31-py3-none-any.whl
Algorithm Hash digest
SHA256 8ec8150a4213951675f711750a4a5b8a98a6da3ef85deeff0bb6e39cd2beeda4
MD5 8bb8601ec09262ced83fa0524199f107
BLAKE2b-256 4f631aa48f7c51ab7442bde592ffe3e996ac2f839e5334fb32d1869416d79cbe

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page