Convert HTML to DOCX format in C# and .NET

  1. Add SautinSoft.Document from Nuget.
  2. Load an input document.
  3. Save to an Images format.

Document .Net can help your application to convert a document from a one format to another.

Complete code

using SautinSoft.Document;

namespace Example
{
    class Program
    {
        static void Main(string[] args)
        {
            ConvertRTFtoImages();
        }

        /// <summary>
        /// Convert RTF to Images (file to file).
        /// </summary>
		/// <remarks>
        /// Details: https://sautinsoft.com/products/document/help/net/developer-guide/convert-rtf-to-images-in-csharp-vb.php
        /// </remarks>
        static void ConvertRTFtoImages()
        {
            // Path to a document where to extract pictures.
            // By the way: You may specify DOCX, HTML, RTF files also.
            DocumentCore dc = DocumentCore.Load(@"..\..\..\example.rtf");

            // PaginationOptions allow to know, how many pages we have in the document.
            DocumentPaginator dp = dc.GetPaginator(new PaginatorOptions());

            // Each document page will be saved in its own image format: PNG, JPEG, TIFF with different DPI.
            dp.Pages[0].Save(@"..\..\..\example.png", new ImageSaveOptions() { DpiX = 800, DpiY = 800 });
            dp.Pages[1].Save(@"..\..\..\example.jpeg", new ImageSaveOptions() { DpiX = 400, DpiY = 400 });
            dp.Pages[2].Save(@"..\..\..\example.tiff", new ImageSaveOptions() { DpiX = 650, DpiY = 650 });

        }
    }
}

Download

Imports SautinSoft.Document

Namespace Example
	Friend Class Program
		Shared Sub Main(ByVal args() As String)
			ConvertRTFtoImages()
		End Sub

		''' <summary>
		''' Convert RTF to Images (file to file).
		''' </summary>
		''' <remarks>
		''' Details: https://sautinsoft.com/products/document/help/net/developer-guide/convert-rtf-to-images-in-csharp-vb.php
		''' </remarks>
		Private Shared Sub ConvertRTFtoImages()
			' Path to a document where to extract pictures.
			' By the way: You may specify DOCX, HTML, RTF files also.
			Dim dc As DocumentCore = DocumentCore.Load("..\..\..\example.rtf")

			' PaginationOptions allow to know, how many pages we have in the document.
			Dim dp As DocumentPaginator = dc.GetPaginator(New PaginatorOptions())

			' Each document page will be saved in its own image format: PNG, JPEG, TIFF with different DPI.
			dp.Pages(0).Save("..\..\..\example.png", New ImageSaveOptions() With {
				.DpiX = 800,
				.DpiY = 800
			})
			dp.Pages(1).Save("..\..\..\example.jpeg", New ImageSaveOptions() With {
				.DpiX = 400,
				.DpiY = 400
			})
			dp.Pages(2).Save("..\..\..\example.tiff", New ImageSaveOptions() With {
				.DpiX = 650,
				.DpiY = 650
			})

		End Sub
	End Class
End Namespace

Download

If you need a new code example or have a question: email us at support@sautinsoft.com or ask at Online Chat (right-bottom corner of this page).