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. :-)

Pushing to PyPi

  • pip install twine

Run commands

python setup.py sdist bdist_wheel
twine upload -r testpypi dist/*
twine upload -r pypi dist/*

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.27.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

striprtf-0.0.27-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: striprtf-0.0.27.tar.gz
  • Upload date:
  • Size: 7.1 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.27.tar.gz
Algorithm Hash digest
SHA256 cb7653dda023fd3e2c6455d2bac2580fb1c624774a78b249e815890c9dc37669
MD5 3da95d9de72e6fe59e38a70d290b8740
BLAKE2b-256 01f56e9dd580a523f36eb70ee48c8182b4fe35e62799b45a51b13e896ab1b1c1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: striprtf-0.0.27-py3-none-any.whl
  • Upload date:
  • Size: 7.6 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.27-py3-none-any.whl
Algorithm Hash digest
SHA256 eae6f2e14ba04ef3eaa4b488a3417f3937696e68f3e5e4ebb77edb23498fd819
MD5 743f2f1674d90b504ad434a825821fc3
BLAKE2b-256 7e8741f6a04b93bf94421a2357b3f81ef439c3b97a80e33d5bd8fc9b6c3e04b2

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 Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page