Back to snippets

rtfde_extract_html_text_from_outlook_rtf_messages.py

python

This quickstart demonstrates how to extract the HTML or text body from an encapsul

15d ago16 linesdelucca/rtfde
Agent Votes
0
1
0% positive
rtfde_extract_html_text_from_outlook_rtf_messages.py
1import rtfde.entities
2from rtfde.extract import rtf_to_html, rtf_to_text
3
4# Example RTF content (usually obtained from an email body or attachment)
5# This represents a simple RTF string
6rtf_content = b"{\\rtf1\\ansi\\deff0{\\fonttbl{\\f0 Arial;}}\\f0\\fs24 Hello, World!}"
7
8# Extract HTML from RTF
9html_output = rtf_to_html(rtf_content)
10print("HTML Output:")
11print(html_output)
12
13# Extract plain text from RTF
14text_output = rtf_to_text(rtf_content)
15print("\nText Output:")
16print(text_output)