VintaSoft Imaging .NET SDK 15.1: Documentation for .NET developer
Vintasoft.Imaging Namespace / DocumentConverter Class
Members Object Syntax Remarks Example Hierarchy Requirements SeeAlso
In This Topic
DocumentConverter Class
In This Topic
Defines the document converter that provides multi-threading optimal algorithm for conversion of image collection to BMP, GIF, JBIG2, JPEG, JPEG2000, PBM, PCX, PDF, PNG, SVG, TIFF, BigTIFF, TGA or WEBP format.
Object Model
ImageCollection IActionProgressController DocumentConverter
Syntax
'Declaration

Public Class DocumentConverter

public class DocumentConverter

Remarks

Use ImageDecodingStarting event to set rendering or decoding setting of input image.
Use ImageEncodingStarting event to process output image before encoding or set encoding setting of output image.

Example

This C#/VB.NET code shows how to convert the document image:


''' <summary>
''' Converts a file from one format to another format.
''' </summary>
''' <param name="inFilename">The input filename.</param>
''' <param name="outFilename">The output filename.</param>
Public Shared Sub Convert(inFilename As String, outFilename As String)
    ' create the document converter
    Using converter As New Vintasoft.Imaging.DocumentConverter()
        ' handle the ImageDecodingStarting event to set decoding setting of an input image
        AddHandler converter.ImageDecodingStarting, AddressOf Converter_ImageDecodingStarting

        ' handle the ImageEncodingStarting event to set encoding setting of an output image
        AddHandler converter.ImageEncodingStarting, AddressOf Converter_ImageEncodingStarting

        ' handle the conversion progress event
        AddHandler converter.ConversionProgress, AddressOf Converter_ConversionProgress

        ' allow multithreading
        converter.MaxThreads = System.Environment.ProcessorCount

        ' add input images to the document converter
        converter.Images.Add(inFilename)

        ' execute conversion
        converter.Convert(outFilename)

        ' clear resources
        converter.Images.ClearAndDisposeItems()
    End Using

    System.Console.WriteLine("Conversion is finished.")
End Sub

''' <summary>
''' Handles the ConversionProgress event of the DocumentConverter.
''' </summary>
''' <param name="sender">The source of the event.</param>
''' <param name="e">The <see cref="Vintasoft.Imaging.ProgressEventArgs"/> instance containing the event data.</param>
Private Shared Sub Converter_ConversionProgress(sender As Object, e As Vintasoft.Imaging.ProgressEventArgs)
    System.Console.WriteLine(String.Format("Conversion {0}%...", e.Progress))
End Sub

''' <summary>
''' Handles the ImageDecodingStarting event of the DocumentConverter.
''' </summary>
''' <param name="sender">The source of the event.</param>
''' <param name="e">The <see cref="Vintasoft.Imaging.ImageDecodingStartingEventArgs"/> instance containing the event data.</param>
Private Shared Sub Converter_ImageDecodingStarting(sender As Object, e As Vintasoft.Imaging.ImageDecodingStartingEventArgs)
    ' if input file is PDF document
    If e.Image.SourceInfo.DecoderName = "Pdf" Then
        ' set the rendring resolution to 150 DPI for input PDF documents
        e.RenderingSettings = New Vintasoft.Imaging.Codecs.Decoders.RenderingSettings(New Vintasoft.Imaging.Resolution(150))
    End If
End Sub

''' <summary>
''' Handles the ImageEncodingStarting event of the DocumentConverter.
''' </summary>
''' <param name="sender">The source of the event.</param>
''' <param name="e">The <see cref="Vintasoft.Imaging.ImageEncodingStartingEventArgs"/> instance containing the event data.</param>
Private Shared Sub Converter_ImageEncodingStarting(sender As Object, e As Vintasoft.Imaging.ImageEncodingStartingEventArgs)
    ' if output file is TIFF file
    If TypeOf e.Encoder Is Vintasoft.Imaging.Codecs.Encoders.TiffEncoder Then
        Dim tiffEncoder As Vintasoft.Imaging.Codecs.Encoders.TiffEncoder = DirectCast(e.Encoder, Vintasoft.Imaging.Codecs.Encoders.TiffEncoder)
        ' if image is black-white image
        If e.Image.BitsPerPixel = 1 Then
            ' use CCITT Group Fax 4 compression
            tiffEncoder.Settings.Compression = Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffCompression.CcittGroup4
        ' if image is grayscale- or RGB-image
        ElseIf e.Image.BitsPerPixel = 8 OrElse e.Image.BitsPerPixel = 24 Then
            ' use JPEG compression
            tiffEncoder.Settings.Compression = Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffCompression.Jpeg
            tiffEncoder.Settings.JpegEncoderSettings.Quality = 70
        Else
            ' use ZIP compression
            tiffEncoder.Settings.Compression = Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffCompression.Zip
        End If
    ' if output file is PDF encoder
    ElseIf TypeOf e.Encoder Is Vintasoft.Imaging.Codecs.Encoders.PdfEncoder Then
        Dim pdfEncoder As Vintasoft.Imaging.Codecs.Encoders.PdfEncoder = DirectCast(e.Encoder, Vintasoft.Imaging.Codecs.Encoders.PdfEncoder)
        ' if image is black-white image
        If e.Image.BitsPerPixel = 1 Then
            ' use CCITT Group Fax 4 compression
            pdfEncoder.Settings.Compression = Vintasoft.Imaging.Codecs.Encoders.PdfImageCompression.CcittFax
        ' if image is grayscale- or RGB-image
        ElseIf e.Image.BitsPerPixel = 8 OrElse e.Image.BitsPerPixel = 24 Then
            ' use JPEG compression
            pdfEncoder.Settings.Compression = Vintasoft.Imaging.Codecs.Encoders.PdfImageCompression.Jpeg
            pdfEncoder.Settings.JpegSettings.Quality = 70
        Else
            ' use ZIP compression
            pdfEncoder.Settings.Compression = Vintasoft.Imaging.Codecs.Encoders.PdfImageCompression.Zip
        End If
    End If
End Sub


/// <summary>
/// Converts a file from one format to another format.
/// </summary>
/// <param name="inFilename">The input filename.</param>
/// <param name="outFilename">The output filename.</param>
public static void Convert(string inFilename, string outFilename)
{
    // create the document converter
    using (Vintasoft.Imaging.DocumentConverter converter = new Vintasoft.Imaging.DocumentConverter())
    {
        // handle the ImageDecodingStarting event to set decoding setting of an input image
        converter.ImageDecodingStarting += Converter_ImageDecodingStarting;

        // handle the ImageEncodingStarting event to set encoding setting of an output image
        converter.ImageEncodingStarting += Converter_ImageEncodingStarting;

        // handle the conversion progress event
        converter.ConversionProgress += Converter_ConversionProgress;

        // allow multithreading
        converter.MaxThreads = System.Environment.ProcessorCount;

        // add input images to the document converter
        converter.Images.Add(inFilename);

        // execute conversion
        converter.Convert(outFilename);

        // clear resources
        converter.Images.ClearAndDisposeItems();
    }

    System.Console.WriteLine("Conversion is finished.");
}

/// <summary>
/// Handles the ConversionProgress event of the DocumentConverter.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="Vintasoft.Imaging.ProgressEventArgs"/> instance containing the event data.</param>
private static void Converter_ConversionProgress(object sender, Vintasoft.Imaging.ProgressEventArgs e)
{
    System.Console.WriteLine(string.Format("Conversion {0}%...", e.Progress));
}

/// <summary>
/// Handles the ImageDecodingStarting event of the DocumentConverter.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="Vintasoft.Imaging.ImageDecodingStartingEventArgs"/> instance containing the event data.</param>
private static void Converter_ImageDecodingStarting(object sender, Vintasoft.Imaging.ImageDecodingStartingEventArgs e)
{
    // if input file is PDF document
    if (e.Image.SourceInfo.DecoderName == "Pdf")
        // set the rendring resolution to 150 DPI for input PDF documents
        e.RenderingSettings = new Vintasoft.Imaging.Codecs.Decoders.RenderingSettings(new Vintasoft.Imaging.Resolution(150));
}

/// <summary>
/// Handles the ImageEncodingStarting event of the DocumentConverter.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="Vintasoft.Imaging.ImageEncodingStartingEventArgs"/> instance containing the event data.</param>
private static void Converter_ImageEncodingStarting(object sender, Vintasoft.Imaging.ImageEncodingStartingEventArgs e)
{
    // if output file is TIFF file
    if (e.Encoder is Vintasoft.Imaging.Codecs.Encoders.TiffEncoder)
    {
        Vintasoft.Imaging.Codecs.Encoders.TiffEncoder tiffEncoder = 
            (Vintasoft.Imaging.Codecs.Encoders.TiffEncoder)e.Encoder;
        // if image is black-white image
        if (e.Image.BitsPerPixel == 1)
        {
            // use CCITT Group Fax 4 compression
            tiffEncoder.Settings.Compression = Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffCompression.CcittGroup4;
        }
        // if image is grayscale- or RGB-image
        else if (e.Image.BitsPerPixel == 8 || e.Image.BitsPerPixel == 24)
        {
            // use JPEG compression
            tiffEncoder.Settings.Compression = Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffCompression.Jpeg;
            tiffEncoder.Settings.JpegEncoderSettings.Quality = 70;
        }
        else
        {
            // use ZIP compression
            tiffEncoder.Settings.Compression = Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffCompression.Zip;
        }
    }
    // if output file is PDF encoder
    else if (e.Encoder is Vintasoft.Imaging.Codecs.Encoders.PdfEncoder)
    {
        Vintasoft.Imaging.Codecs.Encoders.PdfEncoder pdfEncoder = 
            (Vintasoft.Imaging.Codecs.Encoders.PdfEncoder)e.Encoder;
        // if image is black-white image
        if (e.Image.BitsPerPixel == 1)
        {
            // use CCITT Group Fax 4 compression
            pdfEncoder.Settings.Compression = Vintasoft.Imaging.Codecs.Encoders.PdfImageCompression.CcittFax;
        }
        // if image is grayscale- or RGB-image
        else if (e.Image.BitsPerPixel == 8 || e.Image.BitsPerPixel == 24)
        {
            // use JPEG compression
            pdfEncoder.Settings.Compression = Vintasoft.Imaging.Codecs.Encoders.PdfImageCompression.Jpeg;
            pdfEncoder.Settings.JpegSettings.Quality = 70;
        }
        else
        {
            // use ZIP compression
            pdfEncoder.Settings.Compression = Vintasoft.Imaging.Codecs.Encoders.PdfImageCompression.Zip;
        }
    }
}

Inheritance Hierarchy

System.Object
   Vintasoft.Imaging.DocumentConverter

Requirements

Target Platforms: .NET 10; .NET 9; .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

See Also