RtfToHtml Class

An RTF to HTML converter.

Definition

Namespace: MimeKit.Text
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
C#
public class RtfToHtml : TextConverter
Inheritance
Object    TextConverter    RtfToHtml

Remarks

Used to convert Rich Text Format (RTF) documents into HTML.

The converter implements the subset of the Rich Text Format (RTF) Specification, version 1.9.1, that can be meaningfully represented in HTML: character sets and code pages, Unicode escapes, paragraphs and paragraph alignment, line breaks, tables, bold, italic, underline, strikethrough, superscript, subscript, font sizes, foreground and background colors, and HYPERLINK fields. Destinations that do not contain document text (such as pictures, embedded objects, style sheets and document properties) are skipped, as is hidden text. The attachment placeholders (\objattph) that Microsoft Outlook and Exchange write are reported to the AttachmentPlaceholderCallback.

RTF documents that encapsulate HTML (such as those generated by Microsoft Outlook and Exchange), as described by [MS-OXRTFEX], have their original HTML extracted rather than having the RTF rendering of that HTML converted back into HTML. See ExtractEncapsulatedHtml.

The converter is designed to be resilient against hostile input. Its memory usage does not depend on the size of the input: font table, color table and group nesting resources are bounded by MaxFontTableEntries, MaxColorTableEntries and MaxGroupDepth, embedded binary data (\binN) is skipped without being buffered, and only hyperlinks with http, https, mailto, ftp or tel URL schemes are rendered as links.

  Note

Since RTF is a 7-bit format in which non-ASCII characters are escaped, the InputEncoding defaults to ISO-8859-1 so that every byte of the input maps to exactly one character. The code page used to decode escaped characters is determined by the document itself (\ansicpg, \fcharset and \cpg).

  Security Note

Encapsulated HTML is extracted as-is (subject to the HtmlTagCallback), exactly like HtmlToHtml would output it. RtfToHtml is not an HTML sanitizer. For displaying untrusted content, use a dedicated HTML sanitizer library.

Constructors

RtfToHtml Initialize a new instance of the RtfToHtml class.

Properties

AttachmentPlaceholderCallback Get or set the RtfToHtmlAttachmentPlaceholderCallback method to use for rendering attachment placeholders.
ComplianceLogger Get or set the logger to use for reporting RTF compliance violations.
ComplianceOptions Get or set the options that control how RTF compliance violations are reported.
DetectEncodingFromByteOrderMark Get or set whether the encoding of the input is detected from the byte order mark or determined by the InputEncoding property.
(Inherited from TextConverter)
ExtractEncapsulatedHtml Get or set whether HTML encapsulated within the RTF should be extracted.
Footer Get or set the text that will be appended to the end of the output.
(Inherited from TextConverter)
FooterFormat Get or set the footer format.
Header Get or set text that will be prepended to the beginning of the output.
(Inherited from TextConverter)
HeaderFormat Get or set the header format.
HtmlTagCallback Get or set the HtmlTagCallback method to use for custom filtering of HTML tags and content.
InputEncoding Get or set the input encoding.
(Inherited from TextConverter)
InputFormat Get the input format.
(Overrides TextConverterInputFormat)
InputStreamBufferSize Get or set the size of the input stream buffer.
(Inherited from TextConverter)
MaxColorTableEntries Get or set the maximum number of color table entries.
MaxElementDepth Get or set the maximum element depth of encapsulated HTML.
MaxFontTableEntries Get or set the maximum number of font table entries.
MaxGroupDepth Get or set the maximum group depth.
NoScriptHandling Get or set how <noscript> elements in encapsulated HTML should be handled.
OutputEncoding Get or set the output encoding.
(Inherited from TextConverter)
OutputFormat Get the output format.
(Overrides TextConverterOutputFormat)
OutputHtmlFragment Get or set whether the converter should only output an HTML fragment.
OutputStreamBufferSize Get or set the size of the output stream buffer.
(Inherited from TextConverter)

Methods

Convert(String) Convert text from the InputFormat to the OutputFormat.
(Inherited from TextConverter)
Convert(Stream, Stream) Convert the contents of source from the InputFormat to the OutputFormat and writes the resulting text to destination.
(Inherited from TextConverter)
Convert(Stream, TextWriter) Convert the contents of source from the InputFormat to the OutputFormat and uses the writer to write the resulting text.
(Inherited from TextConverter)
Convert(TextReader, TextWriter) Convert the contents of reader from the InputFormat to the OutputFormat and uses the writer to write the resulting text.
(Overrides TextConverterConvert(TextReader, TextWriter))
Convert(TextReader, Stream) Convert the contents of reader from the InputFormat to the OutputFormat and writes the resulting text to destination.
(Inherited from TextConverter)
Equals Determines whether the specified object is equal to the current object.
(Inherited from Object)
Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object)
GetHashCode Serves as the default hash function.
(Inherited from Object)
GetType Gets the Type of the current instance.
(Inherited from Object)
MemberwiseClone Creates a shallow copy of the current Object.
(Inherited from Object)
ToString Returns a string that represents the current object.
(Inherited from Object)

See Also