Skip to main content

RTF parser

Project description

rtfparse

RTF Parser. So far it can only de-encapsulate HTML content from an RTF, but it properly parses the RTF structure and allows you to write your own custom RTF renderers. The HTML de-encapsulator provided with rtfparse is just one such custom renderer which liberates the HTML content from its RTF encapsulation and saves it in a given html file.

Dependencies

argcomplete
extract-msg
compressed_rtf

Installation

Install rtfparse from your local repository with pip:

pip install rtfparse

Installation creates an executable file rtfparse in your python scripts folder which should be in your $PATH.

First Run

When you run rtfparse for the first time it will start a configuration wizard which will guide you through the process of creating a default configuration file and specifying the location of its folders. (These folders serve as locations for saving extracted rtf or html files.)

In the configuration wizard you can press A for care-free automatic configuration, which would look something like this:

$ rtfparse
Config file missing, creating new default config file

 ____ ____ __ _ ____ _ ____ _  _ ____ ____ ___ _ ____ __ _
 |___ [__] | \| |--- | |__, |__| |--< |--|  |  | [__] | \|
 _  _ _ ___  ____ ____ ___
 |/\| |  /__ |--| |--< |__>


◊ email_rtf (C:\Users\nagidal\rtfparse\email_rtf) does not exist!

(A) Automatically configure this and all remaining rtfparse settings
(C) Create this path automatically
(M) Manually input correct path to use or to create
(Q) Quit and edit `email_rtf` in rtfparse_configuration.ini

Created directory C:\Users\nagidal\rtfparse
Created directory C:\Users\nagidal\rtfparse\email_rtf
Created directory C:\Users\nagidal\rtfparse\html

rtfparse also creates the folder .rtfparse (beginning with a dot) in your home directory where it saves its default configuration and its log files.

Usage From Command Line

Use the rtfparse executable from the command line. For example if you want to de-encapsulate the HTML from an RTF file, do it like this:

rtfparse -f "path/to/rtf_file.rtf" -d

Or you can de-encapsulate the HTML from an MS Outlook message, thanks to extract_msg and compressed_rtf:

rtfparse -m "path/to/email.msg" -d

The resulting html file will be saved to the html folder you set in the rtfparse_configuration.ini. Command reference is in rtfparse --help.

Usage in python module

import pathlib
from rtfparse.parser import Rtf_Parser
from rtfparse.renderers import de_encapsulate_html


source_path = pathlib.Path(r"path/to/your/rtf/document.rtf")
target_path = pathlib.Path(r"path/to/your/html/de_encapsulated.html")


parser = Rtf_Parser(rtf_path=source_path)
parsed = parser.parse_file()


renderer = de_encapsulate_html.De_encapsulate_HTML()
with open(target_path, mode="w", encoding="utf-8") as html_file:
    renderer.render(parsed, html_file)

RTF Specification Links

If you find a working official Microsoft link to the RTF specification and add it here, you'll be remembered fondly.

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

rtfparse-0.7.8.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rtfparse-0.7.8-py3-none-any.whl (20.5 kB view details)

Uploaded Python 3

File details

Details for the file rtfparse-0.7.8.tar.gz.

File metadata

  • Download URL: rtfparse-0.7.8.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.9.1

File hashes

Hashes for rtfparse-0.7.8.tar.gz
Algorithm Hash digest
SHA256 0745f0c4fd5e950b9ede88d531ba1eefe8c6fb0186489e8ac8119d19bc265275
MD5 1c11574bcf0a271851603ef82442bd93
BLAKE2b-256 c43310799b7a03acbf3cd0e6795a27ff051999f5c7cf7c5e7956fc69fb6b0712

See more details on using hashes here.

File details

Details for the file rtfparse-0.7.8-py3-none-any.whl.

File metadata

  • Download URL: rtfparse-0.7.8-py3-none-any.whl
  • Upload date:
  • Size: 20.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.1 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.9.1

File hashes

Hashes for rtfparse-0.7.8-py3-none-any.whl
Algorithm Hash digest
SHA256 224741ea8c1b30e0020e5ee75d35d89b39c4e97fa219c37148dfe03bb9823b26
MD5 12aa625f158430bc43dc8a9fc6810538
BLAKE2b-256 d8f63f0d87f7777aef9bdba5f9584d4fcd3b0cfb7bd4b837671d1824d3e37a5b

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