VintaSoft Imaging .NET SDK 15.2: Documentation for .NET developer
In This Topic
Codecs: How to convert a HTML file to a TIFF file?
In This Topic
Here is C#/VB.NET code that shows how to convert a HTML file to a TIFF file using ImageCollection and TiffEncoder classes:
/// <summary>
/// Converts HTML document to TIFF file using ImageCollection and TiffEncoder classes.
/// </summary>
public static void ConvertHtmlToTiff_ImageCollection(string htmlFileName, string tiffFileName)
{
    // create image collection
    using (Vintasoft.Imaging.ImageCollection images = 
        new Vintasoft.Imaging.ImageCollection())
    {
        // layout HTML document on page area: width - 210mm,  height - infinite
        Vintasoft.Imaging.Codecs.Decoders.HtmlLayoutSettings layoutSettings =
            new Vintasoft.Imaging.Codecs.Decoders.HtmlLayoutSettings();
        layoutSettings.PageLayoutSettings.PageSize = 
            Vintasoft.Imaging.ImageSize.FromMillimeters(210, 0, new Vintasoft.Imaging.Resolution(96));
        images.LayoutSettings.SetSettings(layoutSettings);

        // add HTML document to collection
        images.Add(htmlFileName);

        // render HTML pages in 144 DPI
        Vintasoft.Imaging.Codecs.Decoders.RenderingSettings renderingSettings = 
            new Vintasoft.Imaging.Codecs.Decoders.RenderingSettings();
        renderingSettings.Resolution = new Vintasoft.Imaging.Resolution(144);
        images.SetRenderingSettings(renderingSettings);

        // create TiffEncoder
        using (Vintasoft.Imaging.Codecs.Encoders.TiffEncoder encoder = 
            new Vintasoft.Imaging.Codecs.Encoders.TiffEncoder(true))
        {
            // set TIFF compression to Jpeg
            encoder.Settings.Compression = 
                Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffCompression.Jpeg;

            // save images of image collection to TIFF file using TiffEncoder
            images.SaveSync(tiffFileName, encoder);
        }

        // dispose images
        images.ClearAndDisposeItems();
    }
}
''' <summary>
''' Converts HTML document to TIFF file using ImageCollection and TiffEncoder classes.
''' </summary>
Public Shared Sub ConvertHtmlToTiff_ImageCollection(htmlFileName As String, tiffFileName As String)
    ' create image collection
    Using images As New Vintasoft.Imaging.ImageCollection()
        ' layout HTML document on page area: width - 210mm,  height - infinite
        Dim layoutSettings As New Vintasoft.Imaging.Codecs.Decoders.HtmlLayoutSettings()
        layoutSettings.PageLayoutSettings.PageSize = Vintasoft.Imaging.ImageSize.FromMillimeters(210, 0, New Vintasoft.Imaging.Resolution(96))
        images.LayoutSettings.SetSettings(layoutSettings)

        ' add HTML document to collection
        images.Add(htmlFileName)

        ' render HTML pages in 144 DPI
        Dim renderingSettings As New Vintasoft.Imaging.Codecs.Decoders.RenderingSettings()
        renderingSettings.Resolution = New Vintasoft.Imaging.Resolution(144)
        images.SetRenderingSettings(renderingSettings)

        ' create TiffEncoder
        Using encoder As New Vintasoft.Imaging.Codecs.Encoders.TiffEncoder(True)
            ' set TIFF compression to Jpeg
            encoder.Settings.Compression = Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffCompression.Jpeg

            ' save images of image collection to TIFF file using TiffEncoder
            images.SaveSync(tiffFileName, encoder)
        End Using

        ' dispose images
        images.ClearAndDisposeItems()
    End Using
End Sub


Here is C#/VB.NET code that shows how to convert a HTML file to a TIFF file using DocumentConverter class:
/// <summary>
/// Converts HTML document to TIFF file using Vintasoft.Imaging.DocumentConverter class.
/// HTML document is rendered with specified resolution.
/// </summary>
public static void ConvertHtmlToTiff_DocumentConverter(string htmlFileName, string tiffFileName)
{
    // create the document convertor
    Vintasoft.Imaging.DocumentConverter converter = new Vintasoft.Imaging.DocumentConverter();
    
    // subscribe to the DocumentConverter.ImageDecodingStarting event
    converter.ImageDecodingStarting += Converter_ImageDecodingStarting;
    
    // layout HTML document on page area: width - 210mm,  height - infinite
    Vintasoft.Imaging.Codecs.Decoders.HtmlLayoutSettings layoutSettings =
        new Vintasoft.Imaging.Codecs.Decoders.HtmlLayoutSettings();
    layoutSettings.PageLayoutSettings.PageSize =
        Vintasoft.Imaging.ImageSize.FromMillimeters(210, 0, new Vintasoft.Imaging.Resolution(96));
    converter.Images.LayoutSettings.SetSettings(layoutSettings);

    // add HTML pages to the document convertor
    converter.Images.Add(htmlFileName);

    // create TiffEncoder
    using (Vintasoft.Imaging.Codecs.Encoders.TiffEncoder encoder =
        new Vintasoft.Imaging.Codecs.Encoders.TiffEncoder(true))
    {
        // set TIFF compression to Jpeg
        encoder.Settings.Compression =
            Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffCompression.Jpeg;
        // convert HTML pages to TIFF images
        converter.Convert(tiffFileName, encoder);
    }
}

/// <summary>
/// Event handler for the DocumentConverter.ImageDecodingStarting event.
/// </summary>
/// <param name="sender">Object.</param>
/// <param name="e">Event args.</param>
private static void Converter_ImageDecodingStarting(object sender, Vintasoft.Imaging.ImageDecodingStartingEventArgs e)
{
    if (e.RenderingSettings != null)
    {
        // change decoding resolution
        e.RenderingSettings.Resolution = new Vintasoft.Imaging.Resolution(144, 144);
    }
}
''' <summary>
''' Converts HTML document to TIFF file using Vintasoft.Imaging.DocumentConverter class.
''' HTML document is rendered with specified resolution.
''' </summary>
Public Shared Sub ConvertHtmlToTiff_DocumentConverter(htmlFileName As String, tiffFileName As String)
    ' create the document convertor
    Dim converter As New Vintasoft.Imaging.DocumentConverter()

    ' subscribe to the DocumentConverter.ImageDecodingStarting event
    AddHandler converter.ImageDecodingStarting, AddressOf Converter_ImageDecodingStarting

    ' layout HTML document on page area: width - 210mm,  height - infinite
    Dim layoutSettings As New Vintasoft.Imaging.Codecs.Decoders.HtmlLayoutSettings()
    layoutSettings.PageLayoutSettings.PageSize = Vintasoft.Imaging.ImageSize.FromMillimeters(210, 0, New Vintasoft.Imaging.Resolution(96))
    converter.Images.LayoutSettings.SetSettings(layoutSettings)

    ' add HTML pages to the document convertor
    converter.Images.Add(htmlFileName)

    ' create TiffEncoder
    Using encoder As New Vintasoft.Imaging.Codecs.Encoders.TiffEncoder(True)
        ' set TIFF compression to Jpeg
        encoder.Settings.Compression = Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffCompression.Jpeg
        ' convert HTML pages to TIFF images
        converter.Convert(tiffFileName, encoder)
    End Using
End Sub

''' <summary>
''' Event handler for the DocumentConverter.ImageDecodingStarting event.
''' </summary>
''' <param name="sender">Object.</param>
''' <param name="e">Event args.</param>
Private Shared Sub Converter_ImageDecodingStarting(sender As Object, e As Vintasoft.Imaging.ImageDecodingStartingEventArgs)
    If e.RenderingSettings IsNot Nothing Then
        ' change decoding resolution
        e.RenderingSettings.Resolution = New Vintasoft.Imaging.Resolution(144, 144)
    End If
End Sub