### Install RtfPipe via NuGet Source: https://github.com/erdomke/rtfpipe/blob/master/README.md Command to install the RtfPipe package using the NuGet Package Manager console. ```powershell Install-Package RtfPipe ``` -------------------------------- ### Write HTML Output to TextWriter in C# Source: https://context7.com/erdomke/rtfpipe/llms.txt Illustrates how to write the generated HTML directly to a TextWriter, which is useful for streaming or memory-efficient processing of large RTF documents. This example shows writing to a StreamWriter and a StringBuilder. ```csharp using RtfPipe; using System.IO; string rtf = @"{\rtf1\ansi\deff0 {\fonttbl {\f0 Arial;}} \f0\fs20 This is a \i formatted\i0 document. }"; using (var writer = new StreamWriter("output.html")) { Rtf.ToHtml(rtf, writer); } // Or write to a StringBuilder var sb = new StringBuilder(); using (var writer = new StringWriter(sb)) { Rtf.ToHtml(rtf, writer); } string result = sb.ToString(); ``` -------------------------------- ### Calculate and Output Sum in PHP Source: https://github.com/erdomke/rtfpipe/blob/master/RtfPipe.Tests/Files/phprtflite/paragraphs_fonts.html A basic PHP snippet demonstrating variable addition and outputting the result. This illustrates how dynamic data can be processed within the rtfpipe environment. ```php $sum = $a + $b; echo "The sum is - ".$sum." ."; ``` -------------------------------- ### Generating Full HTML Documents Source: https://context7.com/erdomke/rtfpipe/llms.txt Uses the WithFullDocument method to generate complete HTML structures including header, footer, and meta elements. ```csharp using RtfPipe; using RtfPipe.Model; string rtf = @"{\rtf1\ansi\deff0 {\fonttbl {\f0 Arial;}} {\header Header Text\par} {\footer Footer Text\par} Main document content.\par }"; var settings = new RtfHtmlSettings().WithFullDocument(); string html = Rtf.ToHtml(rtf, settings); ``` -------------------------------- ### Custom Image URI Handling in C# Source: https://context7.com/erdomke/rtfpipe/llms.txt Explains how to customize image handling during RTF to HTML conversion using the `ImageUriGetter` callback. This allows for advanced features like converting EMF/WMF metafiles to PNG or saving images to external files. ```csharp using RtfPipe; using System; using System.IO; string rtfWithImage = @"{\rtf1\ansi ...}"; // RTF with embedded image var settings = new RtfHtmlSettings() { ImageUriGetter = picture => { // For EMF or WMF metafiles, convert to PNG using System.Drawing if (picture.Type is EmfBlip || picture.Type is WmMetafile) { using (var source = new MemoryStream(picture.Bytes)) using (var dest = new MemoryStream()) { var bmp = new System.Drawing.Bitmap(source); bmp.Save(dest, System.Drawing.Imaging.ImageFormat.Png); return "data:image/png;base64," + Convert.ToBase64String(dest.ToArray()); } } // For other image types, use the default data URI approach return "data:" + picture.MimeType() + ";base64," + Convert.ToBase64String(picture.Bytes); } }; string html = Rtf.ToHtml(rtfWithImage, settings); ``` -------------------------------- ### Basic RTF to HTML Conversion Source: https://context7.com/erdomke/rtfpipe/llms.txt Demonstrates the simplest way to convert an RTF string to HTML using the static Rtf.ToHtml() method. ```APIDOC ## Basic RTF to HTML Conversion ### Description Converts an RTF string to an HTML string using the `Rtf.ToHtml()` method. ### Method `Rtf.ToHtml(string rtfContent)` ### Endpoint N/A (Library method) ### Parameters #### Request Body - **rtfContent** (string) - Required - The RTF content to convert. ### Request Example ```csharp string rtfContent = @"{\rtf1\ansi\deff0 {\fonttbl {\f0 Times New Roman;}} \f0\fs24 Hello \b World\b0 !\n}"; string html = Rtf.ToHtml(rtfContent); ``` ### Response #### Success Response (200) - **html** (string) - The generated HTML string. #### Response Example ```html

Hello World!

``` ``` -------------------------------- ### Basic RTF to HTML Conversion in C# Source: https://context7.com/erdomke/rtfpipe/llms.txt Demonstrates the simplest way to convert an RTF string to HTML using the static Rtf.ToHtml() method. This method accepts an RTF string and returns a well-formed HTML string. It requires the RtfPipe library and, for .NET Core, the registration of the CodePagesEncodingProvider. ```csharp using RtfPipe; using System.Text; // For .NET Core, register the code pages provider first #if NETCORE Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); #endif // Convert RTF string to HTML string rtfContent = @"{\rtf1\ansi\deff0 {\fonttbl {\f0 Times New Roman;}} \f0\fs24 Hello \b World\b0 !\n}"; string html = Rtf.ToHtml(rtfContent); // Output:

Hello World!

Console.WriteLine(html); ``` -------------------------------- ### Customize Image Conversion in RtfPipe Source: https://github.com/erdomke/rtfpipe/wiki/Documentation Shows how to use RtfHtmlSettings to define a custom ImageUriGetter. This allows for converting specific image types like EMF or WMF into PNG format using System.Drawing before embedding them as base64 strings. ```csharp var html = Rtf.ToHtml(rtf, new RtfHtmlSettings() { ImageUriGetter = picture => { if (picture.Type is EmfBlip || picture.Type is WmMetafile) { using (var source = new MemoryStream(picture.Bytes)) using (var dest = new MemoryStream()) { var bmp = new System.Drawing.Bitmap(source); bmp.Save(dest, System.Drawing.Imaging.ImageFormat.Png); return "data:image/png;base64," + Convert.ToBase64String(dest.ToArray()); } } return "data:" + picture.MimeType() + ";base64," + Convert.ToBase64String(picture.Bytes); } }); ``` -------------------------------- ### RtfHtmlSettings Class Source: https://github.com/erdomke/rtfpipe/wiki/Documentation Configuration options for RTF to HTML conversion. ```APIDOC ## RtfHtmlSettings Class ### Description Provides settings for customizing the conversion of RTF to HTML. ### Constructors #### RtfHtmlSettings() Creates a new instance of the RtfHtmlSettings class with default settings. ### Properties #### AttachmentRenderer - **Type**: `System.Action` - **Description**: Callback used when building the HTML to render an e-mail attachment. #### ElementTags - **Type**: `System.Collections.Generic.Dictionary` - **Description**: Mapping of HTML tags to use for various document element types. #### ImageUriGetter - **Type**: `System.Func` - **Description**: Callback used to get the URI for a picture stored in RTF. This could be a data URI or a link to an external file. ``` -------------------------------- ### Picture Constructors Source: https://github.com/erdomke/rtfpipe/wiki/Documentation Information on the constructors available for the Picture class. ```APIDOC ## Picture.Picture(Group) Constructor Create a new [Picture](#RtfPipe_Picture 'RtfPipe.Picture') object ```csharp public Picture(RtfPipe.Group group); ``` #### Parameters `group` [RtfPipe.Group](https://docs.microsoft.com/en-us/dotnet/api/RtfPipe.Group 'RtfPipe.Group') - An RTF token group ``` -------------------------------- ### Custom Image URI Handling Source: https://context7.com/erdomke/rtfpipe/llms.txt Details how to customize image handling during RTF to HTML conversion using the `ImageUriGetter` callback, including converting metafiles to PNG. ```APIDOC ## Custom Image URI Handling ### Description Allows customization of how embedded images are handled during RTF to HTML conversion by providing an `ImageUriGetter` callback. This can be used to convert image formats or save images to external files. ### Method `Rtf.ToHtml(string rtfContent, RtfHtmlSettings settings)` ### Endpoint N/A (Library method) ### Parameters #### Request Body - **rtfContent** (string) - Required - The RTF content containing images. - **settings** (RtfHtmlSettings) - Optional - Settings object with a custom `ImageUriGetter`. ### Request Example ```csharp using RtfPipe; using System; using System.IO; string rtfWithImage = @"{\rtf1\ansi ...}"; // RTF with embedded image var settings = new RtfHtmlSettings() { ImageUriGetter = picture => { // Convert EMF/WMF metafiles to PNG if (picture.Type is EmfBlip || picture.Type is WmMetafile) { using (var source = new MemoryStream(picture.Bytes)) using (var dest = new MemoryStream()) { var bmp = new System.Drawing.Bitmap(source); bmp.Save(dest, System.Drawing.Imaging.ImageFormat.Png); return "data:image/png;base64," + Convert.ToBase64String(dest.ToArray()); } } // Default handling for other image types return "data:" + picture.MimeType() + ";base64," + Convert.ToBase64String(picture.Bytes); } }; string html = Rtf.ToHtml(rtfWithImage, settings); ``` ### Response #### Success Response (200) - **html** (string) - The generated HTML string with custom image handling applied. #### Response Example ```html ``` ``` -------------------------------- ### Converting RTF from File Stream Source: https://context7.com/erdomke/rtfpipe/llms.txt Shows how to convert an RTF file directly to HTML by using a FileStream. ```APIDOC ## Converting RTF from File Stream ### Description Converts the content of an RTF file to HTML using a `FileStream`. ### Method `Rtf.ToHtml(Stream stream)` ### Endpoint N/A (Library method) ### Parameters #### Request Body - **stream** (Stream) - Required - A readable stream containing the RTF content. ### Request Example ```csharp using System.IO; using (var stream = File.OpenRead("document.rtf")) { string html = Rtf.ToHtml(stream); File.WriteAllText("document.html", html); } ``` ### Response #### Success Response (200) - **html** (string) - The generated HTML string. #### Response Example ```html ``` ``` -------------------------------- ### Rtf.ToHtml Method Signatures Source: https://github.com/erdomke/rtfpipe/wiki/Documentation Provides the method signatures for converting RTF to HTML, supporting output to string, TextWriter, or XmlWriter. ```csharp public static string ToHtml(RtfPipe.RtfSource source, RtfPipe.RtfHtmlSettings settings=null); public static void ToHtml(RtfPipe.RtfSource source, System.IO.TextWriter writer, RtfPipe.RtfHtmlSettings settings=null); public static void ToHtml(RtfPipe.RtfSource source, System.Xml.XmlWriter writer, RtfPipe.RtfHtmlSettings settings=null); ``` -------------------------------- ### Convert RTF to HTML using Rtf.ToHtml in C# Source: https://github.com/erdomke/rtfpipe/wiki/Documentation Demonstrates how to convert an RTF document to HTML using the Rtf.ToHtml method. This overload is useful for creating an HTML document that can be further manipulated. It takes an RTF source, an XmlWriter for output, and optional RtfHtmlSettings. ```csharp var doc = new XDocument(); using (var writer = doc.CreateWriter()) { Rtf.ToHtml(rtf, writer); } ``` -------------------------------- ### Customizing HTML Element Tags Source: https://context7.com/erdomke/rtfpipe/llms.txt Demonstrates how to map RTF document elements to specific HTML tags and attributes using the ElementTags dictionary for semantic output. ```csharp using RtfPipe; using RtfPipe.Model; string rtf = @"{\rtf1\ansi\deff0 {\fonttbl {\f0 Arial;}} {\stylesheet {\s1 Heading 1;}} \pard\s1 Chapter Title\par \pard Normal paragraph text.\par }"; var settings = new RtfHtmlSettings(); // Customize element tag mappings settings.ElementTags[ElementType.Document] = new HtmlTag("article"); settings.ElementTags[ElementType.Paragraph] = new HtmlTag("p") { Attributes = { { "class", "content" } } }; settings.ElementTags[ElementType.Heading1] = new HtmlTag("h1") { Attributes = { { "class", "chapter-title" } } }; string html = Rtf.ToHtml(rtf, settings); ``` -------------------------------- ### RtfHtmlSettings Constructor in C# Source: https://github.com/erdomke/rtfpipe/wiki/Documentation Provides the default constructor for the RtfHtmlSettings class. This allows for the creation of a new RtfHtmlSettings object with default configurations for RTF to HTML conversion. ```csharp public RtfHtmlSettings(); ``` -------------------------------- ### RtfSource Constructor with TextReader (C#) Source: https://github.com/erdomke/rtfpipe/wiki/Documentation Constructs an RtfSource object from a System.IO.TextReader. This is one of the ways to initialize an RtfSource, allowing for RTF content to be read from a text-based input stream. ```csharp public RtfSource(System.IO.TextReader reader); ``` -------------------------------- ### Writing HTML to TextWriter Source: https://context7.com/erdomke/rtfpipe/llms.txt Demonstrates writing the generated HTML directly to a TextWriter, suitable for streaming or memory-efficient processing. ```APIDOC ## Writing HTML to TextWriter ### Description Writes the generated HTML directly to a `TextWriter`, allowing for streaming or writing to various output destinations like files or StringBuilders. ### Method `Rtf.ToHtml(string rtfContent, TextWriter writer)` ### Endpoint N/A (Library method) ### Parameters #### Request Body - **rtfContent** (string) - Required - The RTF content to convert. - **writer** (TextWriter) - Required - The TextWriter to write the HTML output to. ### Request Example ```csharp using System.IO; string rtf = @"{\rtf1\ansi\deff0 {\fonttbl {\f0 Arial;}} \f0\fs20 This is a \i formatted\i0 document. }"; // Writing to a file using (var writer = new StreamWriter("output.html")) { Rtf.ToHtml(rtf, writer); } // Writing to a StringBuilder var sb = new StringBuilder(); using (var writer = new StringWriter(sb)) { Rtf.ToHtml(rtf, writer); } string result = sb.ToString(); ``` ### Response #### Success Response (200) Output is written to the provided `TextWriter`. #### Response Example ```html ``` ``` -------------------------------- ### RtfSource Constructors Source: https://github.com/erdomke/rtfpipe/wiki/Documentation Information on the constructors available for the RtfSource class. ```APIDOC ## RtfSource.RtfSource(TextReader) Constructor Create an RTF source from a reader ```csharp public RtfSource(System.IO.TextReader reader); ``` #### Parameters `reader` [System.IO.TextReader](https://docs.microsoft.com/en-us/dotnet/api/System.IO.TextReader 'System.IO.TextReader') - The [System.IO.TextReader](https://docs.microsoft.com/en-us/dotnet/api/System.IO.TextReader 'System.IO.TextReader') to use ``` -------------------------------- ### Convert RTF File Stream to HTML in C# Source: https://context7.com/erdomke/rtfpipe/llms.txt Shows how to convert an RTF file directly to HTML using a FileStream. This approach is preferred as RTF files can change binary encodings mid-file. The converted HTML is then written to a new file. ```csharp using RtfPipe; using System.IO; using System.Text; #if NETCORE Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); #endif // Convert RTF file to HTML using (var stream = File.OpenRead("document.rtf")) { string html = Rtf.ToHtml(stream); File.WriteAllText("document.html", html); } ``` -------------------------------- ### Convert RTF to HTML using RtfPipe Source: https://github.com/erdomke/rtfpipe/blob/master/README.md This snippet demonstrates how to convert an RTF string into an HTML string. It includes the necessary encoding registration required for .NET Core environments. ```csharp #if NETCORE // Add a reference to the NuGet package System.Text.Encoding.CodePages for .Net core only Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); #endif var html = Rtf.ToHtml(rtf); ``` -------------------------------- ### Picture Constructor with Group (C#) Source: https://github.com/erdomke/rtfpipe/wiki/Documentation Initializes a new instance of the Picture class with a specified RtfPipe.Group. This constructor is used internally to create Picture objects from RTF token groups. ```csharp public Picture(RtfPipe.Group group); ``` -------------------------------- ### Accessing Picture Format Information Source: https://github.com/erdomke/rtfpipe/wiki/Documentation Provides access to the picture format via the Type property and the MimeType method. The MimeType method returns a string representation of the image format. ```csharp public RtfPipe.IToken Type { get; } public string MimeType(); ``` -------------------------------- ### Flexible Input Handling with RtfSource Source: https://context7.com/erdomke/rtfpipe/llms.txt The RtfSource class in RtfPipe supports implicit conversions from various input types including strings, TextReaders, and Streams, providing flexibility in how RTF content is provided to the converter. ```csharp using RtfPipe; using System.IO; // RtfSource accepts multiple input types through implicit conversion // From string string rtfString = @"{\rtf1\ansi Hello}"; string html1 = Rtf.ToHtml(rtfString); // From Stream using (var fileStream = File.OpenRead("document.rtf")) { string html2 = Rtf.ToHtml(fileStream); } // From TextReader using (var reader = new StreamReader("document.rtf")) { string html3 = Rtf.ToHtml(reader); } // Create RtfSource explicitly var source = new RtfSource(new StringReader(@"{\rtf1\ansi Explicit source}")); string html4 = Rtf.ToHtml(source); ``` -------------------------------- ### Implicit Stream to RtfSource Conversion (C#) Source: https://github.com/erdomke/rtfpipe/wiki/Documentation Allows implicit conversion of a System.IO.Stream containing RTF content to an RtfSource object. This is a convenient way to initialize RtfSource from a stream, especially when dealing with binary RTF data. ```csharp public static RtfPipe.RtfSource implicit operator RtfSource(System.IO.Stream value); ``` -------------------------------- ### Writing HTML to XmlWriter for DOM Manipulation Source: https://context7.com/erdomke/rtfpipe/llms.txt Explains how to output RTF conversion results to an XmlWriter, enabling programmatic manipulation of the HTML as an XDocument. ```APIDOC ## Writing HTML to XmlWriter for DOM Manipulation ### Description Outputs the generated HTML to an `XmlWriter`, allowing the creation of an `XDocument` for further programmatic manipulation. ### Method `Rtf.ToHtml(string rtfContent, XmlWriter writer)` ### Endpoint N/A (Library method) ### Parameters #### Request Body - **rtfContent** (string) - Required - The RTF content to convert. - **writer** (XmlWriter) - Required - The XmlWriter to write the HTML output to. ### Request Example ```csharp using System.Xml.Linq; string rtf = @"{\rtf1\ansi\deff0 {\fonttbl {\f0 Verdana;}} \f0\fs24 Document content here. }"; var doc = new XDocument(); using (var writer = doc.CreateWriter()) { Rtf.ToHtml(rtf, writer); } // Manipulate the XDocument var paragraphs = doc.Descendants("p"); foreach (var p in paragraphs) { Console.WriteLine(p.Value); } // Serialize the XDocument string finalHtml = doc.ToString(); ``` ### Response #### Success Response (200) An `XDocument` is created and populated with the HTML output. #### Response Example ```xml ``` ``` -------------------------------- ### Write HTML to XmlWriter for DOM Manipulation in C# Source: https://context7.com/erdomke/rtfpipe/llms.txt Demonstrates outputting RTF to an XmlWriter, enabling the creation of an XDocument for programmatic manipulation. This allows for detailed interaction with the HTML structure after conversion. ```csharp using RtfPipe; using System.Xml.Linq; string rtf = @"{\rtf1\ansi\deff0 {\fonttbl {\f0 Verdana;}} \f0\fs24 Document content here. }"; var doc = new XDocument(); using (var writer = doc.CreateWriter()) { Rtf.ToHtml(rtf, writer); } // Now you can manipulate the XDocument var paragraphs = doc.Descendants("p"); foreach (var p in paragraphs) { Console.WriteLine(p.Value); } // Or serialize it string finalHtml = doc.ToString(); ``` -------------------------------- ### Picture Properties and Methods Source: https://github.com/erdomke/rtfpipe/wiki/Documentation Details regarding the properties and methods of the Picture class, used for handling image data within RTF documents. ```APIDOC ## Picture Properties and Methods ### Description Access properties and methods for image objects extracted from RTF documents. ### Properties - **Bytes** (byte[]) - The binary data describing the picture. - **Height** (UnitValue) - The rendered height of the picture. - **Type** (IToken) - The picture format. - **Width** (UnitValue) - The rendered width of the picture. ### Methods #### MimeType() - **Description**: Returns the MIME type of the picture. - **Returns**: (string) The MIME type string. ``` -------------------------------- ### Rtf.ToHtml Method Source: https://github.com/erdomke/rtfpipe/wiki/Documentation Converts an RTF document to HTML using the specified writer and settings. ```APIDOC ## Rtf.ToHtml ### Description Converts an RTF document to HTML, writing the output to a provided XmlWriter with customizable settings. ### Method This documentation describes a method, not a specific HTTP endpoint. The method signature is: `Rtf.ToHtml(RtfSource source, System.Xml.XmlWriter writer, RtfHtmlSettings settings)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None (This is a method call, not a REST API endpoint) ### Request Example ```csharp var doc = new XDocument(); using (var writer = doc.CreateWriter()) { Rtf.ToHtml(rtf, writer); } ``` ### Response #### Success Response (200) N/A (This is a method call, not a REST API endpoint. Output is written to the provided XmlWriter.) #### Response Example N/A ``` -------------------------------- ### Basic RTF to HTML Conversion Source: https://github.com/erdomke/rtfpipe/wiki/Documentation Converts an RTF string to an HTML string. Ensure to include the 'System.Text.Encoding.CodePages' NuGet package for .Net Core and register the provider. ```APIDOC ## Basic RTF to HTML Conversion ### Description Converts an RTF string to an HTML string. For .Net Core, ensure the `System.Text.Encoding.CodePages` NuGet package is installed and `Encoding.RegisterProvider(CodePagesEncodingProvider.Instance)` is called. ### Method ```csharp public static string ToHtml(string rtf) ``` ### Request Example ```csharp #if NETCORE // Add a reference to the NuGet package System.Text.Encoding.CodePages for .Net core only Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); #endif var html = Rtf.ToHtml(rtf); ``` ### Response Example ```json { "html": "..." } ``` ``` -------------------------------- ### Rtf.ToHtml(RtfSource, RtfHtmlSettings) Source: https://github.com/erdomke/rtfpipe/wiki/Documentation Converts an RTF document to an HTML string using specified settings. ```APIDOC ## Rtf.ToHtml(RtfSource, RtfHtmlSettings) ### Description Converts a Rich Text Format (RTF) document to an HTML string. This method allows for customization of the HTML output through `RtfHtmlSettings`. ### Method ```csharp public static string ToHtml(RtfPipe.RtfSource source, RtfPipe.RtfHtmlSettings settings=null); ``` ### Parameters #### Path Parameters - **source** (RtfSource) - Required - The source RTF document, which can be a String, TextReader, or Stream. - **settings** (RtfHtmlSettings) - Optional - The settings used in the HTML rendering process. ### Returns - **string** - An HTML string representing the converted RTF document. ### Request Example ```csharp // Assuming 'rtfSource' is an RtfPipe.RtfSource object and 'htmlSettings' is an RtfHtmlSettings object string htmlOutput = Rtf.ToHtml(rtfSource, htmlSettings); ``` ### Response Example ```json { "html": "

Converted RTF Content

" } ``` ``` -------------------------------- ### Saving Images to External Files with RtfPipe Source: https://context7.com/erdomke/rtfpipe/llms.txt Configures the ImageUriGetter to extract images from RTF content, save them to a local directory, and return file paths. This reduces HTML size by replacing data URIs with local file references. ```csharp using RtfPipe; using System; using System.IO; string rtfContent = @"{\rtf1\ansi ...}"; // RTF with images string imageFolder = "images"; int imageCounter = 0; Directory.CreateDirectory(imageFolder); var settings = new RtfHtmlSettings() { ImageUriGetter = picture => { imageCounter++; string extension = picture.MimeType() switch { "image/png" => ".png", "image/jpeg" => ".jpg", "image/bmp" => ".bmp", "image/x-emf" => ".emf", _ => ".bin" }; string fileName = $"image_{imageCounter}{extension}"; string filePath = Path.Combine(imageFolder, fileName); File.WriteAllBytes(filePath, picture.Bytes); return $"{imageFolder}/{fileName}"; } }; string html = Rtf.ToHtml(rtfContent, settings); ``` -------------------------------- ### Implicit String to RtfSource Conversion (C#) Source: https://github.com/erdomke/rtfpipe/wiki/Documentation Enables implicit conversion of a string containing RTF content to an RtfSource object. This simplifies the process of creating an RtfSource when the RTF data is available as a string. ```csharp public static RtfPipe.RtfSource implicit operator RtfSource(string value); ``` -------------------------------- ### Rtf.ToHtml(RtfSource, XmlWriter, RtfHtmlSettings) Source: https://github.com/erdomke/rtfpipe/wiki/Documentation Converts an RTF document and writes the resulting HTML to an XmlWriter. ```APIDOC ## Rtf.ToHtml(RtfSource, XmlWriter, RtfHtmlSettings) ### Description Converts a Rich Text Format (RTF) document to HTML and writes the output directly to a specified `System.Xml.XmlWriter`. This method is suitable for scenarios where the HTML needs to be integrated into an XML structure. ### Method ```csharp public static void ToHtml(RtfPipe.RtfSource source, System.Xml.XmlWriter writer, RtfPipe.RtfHtmlSettings settings=null); ``` ### Parameters #### Path Parameters - **source** (RtfSource) - Required - The source RTF document (String, TextReader, or Stream). - **writer** (System.Xml.XmlWriter) - Required - The XmlWriter to which the generated HTML will be written. - **settings** (RtfHtmlSettings) - Optional - The settings used in the HTML rendering. ### Request Example ```csharp // Assuming 'rtfSource' is an RtfPipe.RtfSource object, 'xmlWriter' is a System.Xml.XmlWriter, and 'htmlSettings' is an RtfHtmlSettings object Rtf.ToHtml(rtfSource, xmlWriter, htmlSettings); ``` ### Response Example (This method returns void, output is written to the XmlWriter) ```json { "status": "success", "message": "HTML written to XmlWriter" } ``` ``` -------------------------------- ### RTF to HTML Conversion with Custom Image Handling Source: https://github.com/erdomke/rtfpipe/wiki/Documentation Converts RTF to HTML with custom logic for handling embedded images, such as converting EMF or WMF to PNG. ```APIDOC ## RTF to HTML Conversion with Custom Image Handling ### Description Converts an RTF document to an HTML string, allowing for custom image conversion logic. This is particularly useful for handling embedded images like EMF or WMF by converting them to a standard format like PNG. ### Method ```csharp public static string ToHtml(RtfPipe.RtfSource source, RtfPipe.RtfHtmlSettings settings) ``` ### Parameters #### Request Body - **source** (RtfSource) - Required - The source RTF document (string, TextReader, or Stream). - **settings** (RtfHtmlSettings) - Optional - Settings for HTML rendering, including `ImageUriGetter`. ### Request Example ```csharp var html = Rtf.ToHtml(rtf, new RtfHtmlSettings() { ImageUriGetter = picture => { if (picture.Type is EmfBlip || picture.Type is WmMetafile) { using (var source = new MemoryStream(picture.Bytes)) using (var dest = new MemoryStream()) { var bmp = new System.Drawing.Bitmap(source); bmp.Save(dest, System.Drawing.Imaging.ImageFormat.Png); return "data:image/png;base64," + Convert.ToBase64String(dest.ToArray()); } } return "data:" + picture.MimeType() + ";base64," + Convert.ToBase64String(picture.Bytes); } }); ``` ### Response Example ```json { "html": "......" } ``` ``` -------------------------------- ### Picture Properties Source: https://github.com/erdomke/rtfpipe/wiki/Documentation Details about the properties of the Picture class. ```APIDOC ## Picture.Attributes Property Control tokens stored in the RTF document ```csharp public System.Collections.Generic.IEnumerable Attributes { get; } ``` ``` -------------------------------- ### Rtf.ToHtml(RtfSource, TextWriter, RtfHtmlSettings) Source: https://github.com/erdomke/rtfpipe/wiki/Documentation Converts an RTF document and writes the resulting HTML to a TextWriter. ```APIDOC ## Rtf.ToHtml(RtfSource, TextWriter, RtfHtmlSettings) ### Description Converts a Rich Text Format (RTF) document to HTML and writes the output directly to a specified `System.IO.TextWriter`. This is efficient for large documents as it avoids loading the entire HTML into memory. ### Method ```csharp public static void ToHtml(RtfPipe.RtfSource source, System.IO.TextWriter writer, RtfPipe.RtfHtmlSettings settings=null); ``` ### Parameters #### Path Parameters - **source** (RtfSource) - Required - The source RTF document (String, TextReader, or Stream). - **writer** (System.IO.TextWriter) - Required - The TextWriter to which the generated HTML will be written. - **settings** (RtfHtmlSettings) - Optional - The settings used in the HTML rendering. ### Request Example ```csharp // Assuming 'rtfSource' is an RtfPipe.RtfSource object, 'textWriter' is a System.IO.TextWriter, and 'htmlSettings' is an RtfHtmlSettings object Rtf.ToHtml(rtfSource, textWriter, htmlSettings); ``` ### Response Example (This method returns void, output is written to the TextWriter) ```json { "status": "success", "message": "HTML written to TextWriter" } ``` ``` -------------------------------- ### Low-Level RTF Parsing Source: https://context7.com/erdomke/rtfpipe/llms.txt Utilizes the Parser class to access raw RTF tokens, font tables, and color tables for advanced document analysis. ```csharp using RtfPipe; using RtfPipe.Tokens; using System.IO; using System.Linq; string rtf = @"{\rtf1\ansi\deff0 {\fonttbl {\f0 Times New Roman;}} {\colortbl;\red255\green0\blue0;} \f0\fs24\cf1 Red text.\par }"; var parser = new Parser(rtf); var document = parser.Parse(); Console.WriteLine($"Has HTML encapsulation: {document.HasHtml}"); Console.WriteLine($"Font count: {document.FontTable.Count}"); Console.WriteLine($"Color count: {document.ColorTable.Count}"); foreach (var font in document.FontTable) { Console.WriteLine($"Font {font.Key}: {font.Value.Name}"); } for (int i = 0; i < document.ColorTable.Count; i++) { var color = document.ColorTable[i]; Console.WriteLine($"Color {i}: RGB({color.Red}, {color.Green}, {color.Blue})"); } var tokens = parser.Tokens().ToList(); Console.WriteLine($"Total tokens: {tokens.Count}"); ``` -------------------------------- ### Implicit TextReader to RtfSource Conversion (C#) Source: https://github.com/erdomke/rtfpipe/wiki/Documentation Facilitates implicit conversion of a System.IO.TextReader containing RTF content to an RtfSource object. This provides a straightforward method for creating an RtfSource from a text reader. ```csharp public static RtfPipe.RtfSource implicit operator RtfSource(System.IO.TextReader value); ``` -------------------------------- ### Customizing Attachment Rendering Source: https://context7.com/erdomke/rtfpipe/llms.txt Implements the AttachmentRenderer callback to define custom HTML output for email attachments found within RTF content. ```csharp using RtfPipe; using System.Xml; string rtfFromOutlook = @"{\rtf1\ansi ...}"; // RTF with attachments var settings = new RtfHtmlSettings() { AttachmentRenderer = (index, writer) => { writer.WriteStartElement("div"); writer.WriteAttributeString("class", "attachment"); writer.WriteAttributeString("data-attachment-index", index.ToString()); writer.WriteStartElement("span"); writer.WriteAttributeString("class", "attachment-icon"); writer.WriteString("[Attachment " + (index + 1) + "]"); writer.WriteEndElement(); writer.WriteEndElement(); } }; string html = Rtf.ToHtml(rtfFromOutlook, settings); ``` -------------------------------- ### RtfSource Implicit Operators Source: https://github.com/erdomke/rtfpipe/wiki/Documentation Information on the implicit conversion operators for the RtfSource class, allowing conversion from String, Stream, and TextReader. ```APIDOC ## RtfSource.implicit operator RtfSource(string) Operator Implicitly convert strings containing RTF content to an [RtfSource](#RtfPipe_RtfSource 'RtfPipe.RtfSource') ```csharp public static RtfPipe.RtfSource implicit operator RtfSource(string value); ``` #### Parameters `value` [System.String](https://docs.microsoft.com/en-us/dotnet/api/System.String 'System.String') - RTF content #### Returns [RtfSource](#RtfPipe_RtfSource 'RtfPipe.RtfSource') ## RtfSource.implicit operator RtfSource(Stream) Operator Implicitly convert a [System.IO.Stream](https://docs.microsoft.com/en-us/dotnet/api/System.IO.Stream 'System.IO.Stream') containing RTF content to an [RtfSource](#RtfPipe_RtfSource 'RtfPipe.RtfSource') ```csharp public static RtfPipe.RtfSource implicit operator RtfSource(System.IO.Stream value); ``` #### Parameters `value` [System.IO.Stream](https://docs.microsoft.com/en-us/dotnet/api/System.IO.Stream 'System.IO.Stream') - RTF content #### Returns [RtfSource](#RtfPipe_RtfSource 'RtfPipe.RtfSource') ## RtfSource.implicit operator RtfSource(TextReader) Operator Implicitly convert a [System.IO.TextReader](https://docs.microsoft.com/en-us/dotnet/api/System.IO.TextReader 'System.IO.TextReader') containing RTF content to an [RtfSource](#RtfPipe_RtfSource 'RtfPipe.RtfSource') ```csharp public static RtfPipe.RtfSource implicit operator RtfSource(System.IO.TextReader value); ``` #### Parameters `value` [System.IO.TextReader](https://docs.microsoft.com/en-us/dotnet/api/System.IO.TextReader 'System.IO.TextReader') - RTF content #### Returns [RtfSource](#RtfPipe_RtfSource 'RtfPipe.RtfSource') ``` -------------------------------- ### Accessing Picture Binary Data Source: https://github.com/erdomke/rtfpipe/wiki/Documentation Retrieves the raw binary byte array representing the picture content. This property is read-only. ```csharp public byte[] Bytes { get; } ``` -------------------------------- ### Accessing Picture Dimensions Source: https://github.com/erdomke/rtfpipe/wiki/Documentation Retrieves the rendered width and height of the picture as UnitValue objects. These properties define the display size within the document. ```csharp public RtfPipe.UnitValue Height { get; } public RtfPipe.UnitValue Width { get; } ``` -------------------------------- ### RtfSource Class Definition (C#) Source: https://github.com/erdomke/rtfpipe/wiki/Documentation Defines the RtfSource class, which serves as a source for RTF content. It supports auto-conversion from String, TextReader, or Stream, with Stream being preferred for handling potential binary encoding changes within RTF files. ```csharp public class RtfSource ``` -------------------------------- ### RtfSource Properties Source: https://github.com/erdomke/rtfpipe/wiki/Documentation Details about the properties of the RtfSource class. ```APIDOC ## RtfSource.Reader Property A reader used to read text from the source ```csharp public System.IO.TextReader Reader { get; } ``` #### Property Value [System.IO.TextReader](https://docs.microsoft.com/en-us/dotnet/api/System.IO.TextReader 'System.IO.TextReader') ``` -------------------------------- ### Converting RTF Lists to HTML Source: https://context7.com/erdomke/rtfpipe/llms.txt RtfPipe supports the conversion of both bulleted and numbered lists found in RTF documents, preserving their structure and nesting, into corresponding HTML list elements (
    and
      ). ```csharp using RtfPipe; string rtfList = @"{\rtf1\ansi\deff0 {\fonttbl {\f0 Arial;}} {\listtext\pard\fi-360\li720\bullet\tab}Item 1\par {\listtext\pard\fi-360\li720\bullet\tab}Item 2\par {\listtext\pard\fi-360\li720\bullet\tab}Item 3\par }"; string html = Rtf.ToHtml(rtfList); // Converts to
      • Item 1
      • Item 2
      • Item 3
      ``` -------------------------------- ### RtfSource Class Source: https://github.com/erdomke/rtfpipe/wiki/Documentation Details about the RtfSource class, which represents a source of RTF content and supports auto-conversion from String, TextReader, and Stream. ```APIDOC ## RtfSource Class Represents a source of RTF content. It auto-converts from either a [System.String](https://docs.microsoft.com/en-us/dotnet/api/System.String 'System.String'), [System.IO.TextReader](https://docs.microsoft.com/en-us/dotnet/api/System.IO.TextReader 'System.IO.TextReader'), or [System.IO.Stream](https://docs.microsoft.com/en-us/dotnet/api/System.IO.Stream 'System.IO.Stream'). Using a [System.IO.Stream](https://docs.microsoft.com/en-us/dotnet/api/System.IO.Stream 'System.IO.Stream') is preferred as an RTF file can switch binary encodings in the middle of a file. ```csharp public class RtfSource ``` Inheritance [System.Object](https://docs.microsoft.com/en-us/dotnet/api/System.Object 'System.Object') 🡒 RtfSource ``` -------------------------------- ### RtfHtmlSettings Class Definition in C# Source: https://github.com/erdomke/rtfpipe/wiki/Documentation Defines the RtfHtmlSettings class, which is used to configure the conversion of RTF to HTML. It inherits from RtfPipe.HtmlWriterSettings and provides properties for customizing attachment rendering, element tag mapping, and image URI retrieval. ```csharp public class RtfHtmlSettings : RtfPipe.HtmlWriterSettings { public System.Action AttachmentRenderer { get; set; } public System.Collections.Generic.Dictionary ElementTags { get; } public System.Func ImageUriGetter { get; set; } } ``` -------------------------------- ### Converting RTF Tables to HTML Source: https://context7.com/erdomke/rtfpipe/llms.txt RtfPipe effectively handles the conversion of RTF documents containing complex table structures, including nested tables, merged cells, and custom borders, into standard HTML table elements. ```csharp using RtfPipe; string rtfTable = @"{\rtf1\ansi\deff0 {\fonttbl {\f0 Arial;}} \trowd\cellx2000\cellx4000\cellx6000 \intbl Cell 1\cell Cell 2\cell Cell 3\cell\row \trowd\cellx2000\cellx4000\cellx6000 \intbl Row 2 A\cell Row 2 B\cell Row 2 C\cell\row }"; string html = Rtf.ToHtml(rtfTable); // Produces: ...
      Cell 1Cell 2Cell 3
      ``` -------------------------------- ### Picture Attributes Property (C#) Source: https://github.com/erdomke/rtfpipe/wiki/Documentation Retrieves the control tokens associated with a picture in the RTF document. This property returns an enumerable collection of IToken objects representing the attributes of the picture. ```csharp public System.Collections.Generic.IEnumerable Attributes { get; } ``` -------------------------------- ### Picture Class Source: https://github.com/erdomke/rtfpipe/wiki/Documentation Details about the Picture class, which represents a picture stored within an RTF document. ```APIDOC ## Picture Class A picture store in a RTF document ```csharp public class Picture : RtfPipe.Model.Node ``` Inheritance [System.Object](https://docs.microsoft.com/en-us/dotnet/api/System.Object 'System.Object') 🡒 [Node](#RtfPipe_Model_Node 'RtfPipe.Model.Node') 🡒 Picture ``` -------------------------------- ### Accessing Embedded Image Metadata with Picture Class Source: https://context7.com/erdomke/rtfpipe/llms.txt The Picture class allows access to metadata of embedded images within RTF, including dimensions, format, and raw byte data. This is useful for custom image handling or data extraction. ```csharp using RtfPipe; using RtfPipe.Model; using System; using System.IO; var settings = new RtfHtmlSettings() { ImageUriGetter = picture => { // Access picture properties Console.WriteLine($"MIME Type: {picture.MimeType()}"); Console.WriteLine($"Width: {picture.Width}"); Console.WriteLine($"Height: {picture.Height}"); Console.WriteLine($"Byte size: {picture.Bytes.Length}"); Console.WriteLine($"Format token: {picture.Type}"); // picture.MimeType() returns one of: // - "image/png" for PNG images // - "image/jpeg" for JPEG images // - "image/bmp" for BMP images // - "image/x-emf" for EMF metafiles // - "windows/metafile" for WMF metafiles // - "image/x-pict" for Mac PICT images return "data:" + picture.MimeType() + ";base64," + Convert.ToBase64String(picture.Bytes); } }; string html = Rtf.ToHtml(rtfWithImages, settings); ``` -------------------------------- ### RtfSource Reader Property (C#) Source: https://github.com/erdomke/rtfpipe/wiki/Documentation Provides access to the TextReader used by the RtfSource. This property allows retrieval of the underlying reader, which is utilized for reading text content from the RTF source. ```csharp public System.IO.TextReader Reader { get; } ``` -------------------------------- ### Processing HTML-Encapsulated RTF (Outlook) Source: https://context7.com/erdomke/rtfpipe/llms.txt RtfPipe automatically detects and extracts HTML content embedded within RTF, a common format produced by Microsoft Outlook. This allows for the direct conversion of email body content. ```csharp using RtfPipe; // RTF with encapsulated HTML (from Outlook emails) string outlookRtf = @"{\rtf1\ansi\ansicpg1252\fromhtml1 \deff0{\fonttbl {\f0\fswiss\fcharset0 Arial;}} {\colortbl\red0\green0\blue0;} \uc1\pard\plain\deftab360 \f0\fs24 {\*\htmltag18 } {\*\htmltag50 }\htmlrtf \lang1033 \htmlrtf0 {\*\htmltag148 }\htmlrtf {\htmlrtf0 Hello World {\*\htmltag156 }\htmlrtf } {\*\htmltag58 } {\*\htmltag27 }}"; // RtfPipe automatically extracts the original HTML string html = Rtf.ToHtml(outlookRtf); // Output: Hello World ``` -------------------------------- ### Picture Class Definition (C#) Source: https://github.com/erdomke/rtfpipe/wiki/Documentation Represents a picture embedded within an RTF document. This class inherits from RtfPipe.Model.Node and is used to store and manage image data found in RTF files. ```csharp public class Picture : RtfPipe.Model.Node ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.