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

        // add Email document to collection
        images.Add(emailFileName);

        // render Email 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))
        {
            // specify that TIFF encoder should use Jpeg compression for image data
            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 Email (.msg, .eml) document to TIFF file using ImageCollection and TiffEncoder classes.
''' </summary>
Public Shared Sub ConvertEmailToTiff_ImageCollection(emailFileName As String, tiffFileName As String)
    ' create image collection
    Using images As New Vintasoft.Imaging.ImageCollection()
        ' layout Email document on page area: width - 210mm,  height - infinite
        Dim layoutSettings As New Vintasoft.Imaging.Codecs.Decoders.EmailLayoutSettings()
        layoutSettings.PageLayoutSettings.PageSize = _
            Vintasoft.Imaging.ImageSize.FromMillimeters(210, 0, New Vintasoft.Imaging.Resolution(96))
        images.LayoutSettings.SetSettings(layoutSettings)

        ' add Email document to collection
        images.Add(emailFileName)

        ' render Email 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)
            ' specify that TIFF encoder should use Jpeg compressin for image data
            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 an Email file to a TIFF file using DocumentConverter class:
/// <summary>
/// Converts Email (.msg, .eml) document file to TIFF file using Vintasoft.Imaging.DocumentConverter class.
/// Email document is rendered with specified resolution.
/// </summary>
public static void ConvertEmailToTiff_DocumentConverter(string emailFileName, 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 Email document on page area: width - 210mm,  height - infinite
    Vintasoft.Imaging.Codecs.Decoders.EmailLayoutSettings layoutSettings =
        new Vintasoft.Imaging.Codecs.Decoders.EmailLayoutSettings();
    layoutSettings.PageLayoutSettings.PageSize =
        Vintasoft.Imaging.ImageSize.FromMillimeters(210, 0, new Vintasoft.Imaging.Resolution(96));
    converter.Images.LayoutSettings.SetSettings(layoutSettings);

    // add Email pages to the document convertor
    converter.Images.Add(emailFileName);

    // 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 Email 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 Email (.msg, .eml) document file to TIFF file using Vintasoft.Imaging.DocumentConverter class.
''' Email document is rendered with specified resolution.
''' </summary>
Public Shared Sub ConvertEmailToTiff_DocumentConverter(emailFileName 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 Email document on page area: width - 210mm,  height - infinite
    Dim layoutSettings As New Vintasoft.Imaging.Codecs.Decoders.EmailLayoutSettings()
    layoutSettings.PageLayoutSettings.PageSize = Vintasoft.Imaging.ImageSize.FromMillimeters(210, 0, New Vintasoft.Imaging.Resolution(96))
    converter.Images.LayoutSettings.SetSettings(layoutSettings)

    ' add Email pages to the document convertor
    converter.Images.Add(emailFileName)

    ' 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 Email 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