Click or drag to resize

RtfToHtmlHtmlSaveOptionsProduceOnlyHtmlBody Property

Gets or sets a value to produce a complete HTML document or only between between <body>...</body> tags. Default value: false.

Namespace: SautinSoft
Assembly: SautinSoft.RtfToHtml (in SautinSoft.RtfToHtml.dll) Version: 2024.6.6
public bool ProduceOnlyHtmlBody { get; set; }

Property Value

In case of 'True' you will get only HTML between <body>...</body> tags.
This property will be useful to merge multiply HTML documents into a single.
Produce only HTML body in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using SautinSoft;

namespace Example
    class Program
        static void Main(string[] args)
        /// <summary>
        /// How to produce HTML document only between &lt;body&gt;...&lt;/body&gt; tags.
        /// </summary>
        static void ProduceOnlyHtmlBody()
            string inpFile = @"..\..\..\example.docx";
            string outFile = @"Result.html";

            RtfToHtml r = new RtfToHtml();

            // Set properties to produce HTML document only
            // between &lt;body&gt;...&lt;/body&gt; tags
            RtfToHtml.HtmlFlowingSaveOptions opt = new RtfToHtml.HtmlFlowingSaveOptions()
                ProduceOnlyHtmlBody = true

                r.Convert(inpFile, outFile, opt);
            catch (Exception ex)
                Console.WriteLine($"Conversion failed! {ex.Message}");

            // Open the result.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
Produce only HTML body in VB.Net
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.IO
Imports SautinSoft

Namespace Example
    Friend Class Program
        Shared Sub Main(ByVal args() As String)
        End Sub
        ''' <summary>
        ''' How to produce HTML document only between &lt;body&gt;...&lt;/body&gt; tags.
        ''' </summary>
        Private Shared Sub ProduceOnlyHtmlBody()
            Dim inpFile As String = "..\..\..\example.docx"
            Dim outFile As String = "Result.html"

            Dim r As New RtfToHtml()

            ' Set properties to produce HTML document only
            ' between &lt;body&gt;...&lt;/body&gt; tags
            Dim opt As New RtfToHtml.HtmlFlowingSaveOptions() With {
                .ProduceOnlyHtmlBody = True

                r.Convert(inpFile, outFile, opt)
            Catch ex As Exception
                Console.WriteLine($"Conversion failed! {ex.Message}")
            End Try

            ' Open the result.
            System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(outFile) With {.UseShellExecute = True})
        End Sub
    End Class
End Namespace
See Also