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

Uploaded Python 3

File details

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

File metadata

  • Download URL: rtfparse-0.7.7.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.7.tar.gz
Algorithm Hash digest
SHA256 75898084669d06b88a1eaba971d834b446ca599e9c4df89d9a88d3157088846a
MD5 883fde08e29cd9cf0ed2758aa2e51fe6
BLAKE2b-256 39bdf749be47ee48ee13c84e638d0ba3712acea0122c7f1930e734da76c4ee5b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rtfparse-0.7.7-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.7-py3-none-any.whl
Algorithm Hash digest
SHA256 6a95e8381009a6f2e94637580576ec19383a14371cf6663c5ed120c5ad817d63
MD5 f34b8af2623332f126d6dd5b7a6927d3
BLAKE2b-256 8b51738fd543d62ff03e3227632fc176634b6eb37566e394a135233045cd2577

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