Click or drag to resize

HtmlLoadOptions Class

Represents a class that stores loading options for HyperText Markup Language (HTML) format.
Inheritance Hierarchy

Namespace:  SautinSoft.Document
Assembly:  SautinSoft.Document (in SautinSoft.Document.dll) Version: 4.0.11.12 (4.0.11.12)
Syntax
public sealed class HtmlLoadOptions : LoadOptions

The HtmlLoadOptions type exposes the following members.

Constructors
  NameDescription
Public methodCode exampleHtmlLoadOptions
Initializes a new instance of the HtmlLoadOptions class.
Top
Properties
  NameDescription
Public propertyBaseAddress
Gets or sets the base address for images with relative location.
Public propertyEncoding
Gets or sets the encoding for the HTML file.
Public propertyPageSetup
Public propertyPreserveHyperlinks
Get and set the value whether to preserve hyperlinks during the HTML loading or skip them. Default value: true.
Public propertyPreserveUnsupportedFeatures
Gets or sets a value indicating whether to preserve file format features that are not directly supported.
(Inherited from LoadOptions.)
Public propertyTableFastProcessing
Get and set the value indicating how launch the table auto-fit algorithm: Fast with middle accuracy (true) or Slow with the maximal accuracy (false). Default value: false.
Public propertyTableFitWidthByPage
Gets or sets a value indicating to automatically decrease a table width if it greater than page width. Default value: true.
Top
Methods
  NameDescription
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Examples
How to load a HTML document in C#
using System;
using System.IO;
using SautinSoft.Document;

namespace Example
{
    class Program
    {

        static void Main(string[] args)
        {
            LoadHtmlFromFile();
            //LoadHtmlFromStream();
        }

        /// <summary>
        /// Loads an HTML document into DocumentCore (dc) from a file.
        /// </summary>
        /// <remarks>
        /// Details: https://www.sautinsoft.com/products/document/examples/load-html-document-net-csharp-vb.php
        /// </remarks>
        static void LoadHtmlFromFile()
        {
            string filePath = @"..\..\example.html";
            // The file format is detected automatically from the file extension: ".html".
            // But as shown in the example below, we can specify HtmlLoadOptions as 2nd parameter
            // to explicitly set that a loadable document has HTML format.
            DocumentCore dc = DocumentCore.Load(filePath);
            if (dc != null)
                Console.WriteLine("Loaded successfully!");

            Console.ReadKey();            
        }

        /// <summary>
        /// Loads an HTML document into DocumentCore (dc) from a MemoryStream.
        /// </summary>
        /// <remarks>
        /// Details: https://www.sautinsoft.com/products/document/examples/load-html-document-net-csharp-vb.php
        /// </remarks>
        static void LoadHtmlFromStream()
        {
            // Get document bytes.
            byte[] fileBytes = File.ReadAllBytes(@"..\..\example.html");

            DocumentCore dc = null;

            // Create a MemoryStream
            using (MemoryStream ms = new MemoryStream(fileBytes))
            {
                // Load a document from the MemoryStream.
                // Specifying HtmlLoadOptions we explicitly set that a loadable document is HTML.
                dc = DocumentCore.Load(ms, new HtmlLoadOptions());
            }
            if (dc != null)
                Console.WriteLine("Loaded successfully!");

            Console.ReadKey();            
        }
    }
}
How to load a HTML document in VB.Net
Imports System
Imports System.IO
Imports SautinSoft.Document

Module Sample
    Sub Main()
        LoadHtmlFromFile()
        'LoadHtmlFromStream();
    End Sub

    ''' <summary>
    ''' Loads an HTML document into DocumentCore (dc) from a file.
    ''' </summary>
    ''' <remarks>
    ''' Details: https://www.sautinsoft.com/products/document/examples/load-html-document-net-csharp-vb.php
    ''' </remarks>
    Sub LoadHtmlFromFile()
        Dim filePath As String = "..\example.html"
        ' The file format is detected automatically from the file extension: ".html".
        ' But as shown in the example below, we can specify HtmlLoadOptions as 2nd parameter
        ' to explicitly set that a loadable document has HTML format.
        Dim dc As DocumentCore = DocumentCore.Load(filePath)
        If dc IsNot Nothing Then
            Console.WriteLine("Loaded successfully!")
        End If

        Console.ReadKey()
    End Sub

    ''' <summary>
    ''' Loads an HTML document into DocumentCore (dc) from a MemoryStream.
    ''' </summary>
    ''' <remarks>
    ''' Details: https://www.sautinsoft.com/products/document/examples/load-html-document-net-csharp-vb.php
    ''' </remarks>
    Sub LoadHtmlFromStream()
        ' Get document bytes.
        Dim fileBytes() As Byte = File.ReadAllBytes("..\example.html")

        Dim dc As DocumentCore = Nothing

        ' Create a MemoryStream
        Using ms As New MemoryStream(fileBytes)
            ' Load a document from the MemoryStream.
            ' Specifying HtmlLoadOptions we explicitly set that a loadable document is HTML.
            dc = DocumentCore.Load(ms, New HtmlLoadOptions())
        End Using
        If dc IsNot Nothing Then
            Console.WriteLine("Loaded successfully!")
        End If

        Console.ReadKey()        
    End Sub
End Module
See Also