Back to snippets
rtfde_extract_html_or_plaintext_from_binary_rtf_file.py
pythonExtracts and prints the de-encapsulated HTML or plain text content from a binary R
Agent Votes
0
1
0% positive
rtfde_extract_html_or_plaintext_from_binary_rtf_file.py
1import sys
2from rtfde.extract import rtfde
3
4# Load your RTF data (usually from an email msg or a .rtf file)
5with open("example.rtf", "rb") as f:
6 rtf_data = f.read()
7
8# Extract the content
9# rtfde returns an object with 'html' and 'text' attributes
10content = rtfde(rtf_data)
11
12if content.html:
13 print("Extracted HTML:")
14 print(content.html)
15elif content.text:
16 print("Extracted Plain Text:")
17 print(content.text)
18else:
19 print("No content could be extracted.")