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.32.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.32-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: striprtf-0.0.32.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.32.tar.gz
Algorithm Hash digest
SHA256 7f375a375d99a2700842173168c90c9b545cb244241ffc5d868ed9f6baf9155f
MD5 e669bc7c88610b32d340b39332cff9ab
BLAKE2b-256 86f9b3ecbd2e0abb9c29edd2913482f0c5df47a098221444ccd50cc5cd3f9b91

See more details on using hashes here.

File details

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

File metadata

  • Download URL: striprtf-0.0.32-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.32-py3-none-any.whl
Algorithm Hash digest
SHA256 9f695fea9662cb4ffccf2b56286b3e77028c0a61e87258719584e681e0144869
MD5 08eb412282fbb0a0bd7504891749db67
BLAKE2b-256 c3cf4157959aa36a567faab32a5fb078904b76654bdd86a3d7f8fba21ed89d84

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