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

Uploaded Source

Built Distribution

striprtf-0.0.29-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: striprtf-0.0.29.tar.gz
  • Upload date:
  • Size: 7.5 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.29.tar.gz
Algorithm Hash digest
SHA256 5a822d075e17417934ed3add6fc79b5fc8fb544fe4370b2f894cdd28f0ddd78e
MD5 088431754e968ea36b689ee10280f3b4
BLAKE2b-256 f3867154b7c625a3ff704581dab70c05389e1de90233b7a751f79f712c2ca0e9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: striprtf-0.0.29-py3-none-any.whl
  • Upload date:
  • Size: 7.9 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.29-py3-none-any.whl
Algorithm Hash digest
SHA256 0fc6a41999d015358d19627776b616424dd501ad698105c81d76734d1e14d91b
MD5 7425062c01337ff526149a40a621f9e3
BLAKE2b-256 083e1418afacc4aae04690cff282078f22620c89a99490499878ececc3021654

See more details on using hashes here.

Supported by

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