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

Uploaded Python 3

File details

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

File metadata

  • Download URL: striprtf-0.0.30.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.30.tar.gz
Algorithm Hash digest
SHA256 29178c170dbecaceece17ce451561d8ec2a77c3bf4a82cec931fe37ea22c2aee
MD5 63b7a54b91de29df64ba30a3b435f861
BLAKE2b-256 6ba840fe8c6c833d8e1157673d977601d22f73d76e55af4759cfef76daf5d385

See more details on using hashes here.

File details

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

File metadata

  • Download URL: striprtf-0.0.30-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.30-py3-none-any.whl
Algorithm Hash digest
SHA256 7d782e7cdda0088774ace35e39b97d3c161046f649c1321d7651341bdbee565d
MD5 8d846b6074e41c9a9f1b3cfa0ae08f15
BLAKE2b-256 73ac12de961b43e37ad8e23a7dcdb8b7867471a7f4fbe09608191523292ce3b4

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