Skip to main content

A simple library to convert rtf to text

Project description

striprtf

Build status

Purpose

This is a simple library to convert Rich Text Format (RTF) files to python strings. 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.28.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

striprtf-0.0.28-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: striprtf-0.0.28.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6

File hashes

Hashes for striprtf-0.0.28.tar.gz
Algorithm Hash digest
SHA256 902806a2e0821faf412130450bdbb84f15e996a729061a51fe7286c620b6fee3
MD5 0222912f3ae7c5e352e6853df2db4575
BLAKE2b-256 da3db3806c11f90f795284ab19b9561d547779ba8c3acc22a3907ac6afe9ec61

See more details on using hashes here.

File details

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

File metadata

  • Download URL: striprtf-0.0.28-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6

File hashes

Hashes for striprtf-0.0.28-py3-none-any.whl
Algorithm Hash digest
SHA256 d441f32aeb730c347ccbbbbb06a057b8df1a4e46df0bdb9fca548c601988929c
MD5 903715ca9c10dfb7274c3b9066d67d00
BLAKE2b-256 9b6318dc0365c0d3edc7e81a3c1cef2015079fdf58c8b681fa79ad952be7925b

See more details on using hashes here.

Supported by

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