VintaSoft Imaging .NET SDK 12.4: Documentation for .NET developer
In This Topic
    Codecs: How to convert PDF to TIFF?
    In This Topic
    VintaSoft Imaging .NET SDK renders PDF page (draws text, images and graphics on PDF page) when converting PDF document to a TIFF file.

    By default SDK:

    You need override algorithm for searching external fonts if PDF document contains not standard external fonts. This can be done using the FileFontProgramsControllerWithFallbackFont class.
    More info about fonts in PDF document can be found here.

    VintaSoft Imaging .NET SDK allows to convert PDF document to a TIFF file using 3 ways: DocumentConverter, ImageCollection, TiffFile. Usage of DocumentConverter class provides the best performance because DocumentConverter class uses multi-threading.


    Here is C#/VB.NET code that shows how to convert PDF document with default resolution (96 dpi) to TIFF file using DocumentConverter class:
    /// <summary>
    /// Converts PDF document to a TIFF file using Vintasoft.Imaging.DocumentConverter class.
    /// </summary>
    public static void ConvertPdfToTiff_DocumentConverter(string pdfFileName, string tiffFileName)
    {
        Vintasoft.Imaging.DocumentConverter.Convert(pdfFileName, tiffFileName);
    }
    
    ''' <summary>
    ''' Converts PDF document to a TIFF file using Vintasoft.Imaging.DocumentConverter class.
    ''' </summary>
    Public Shared Sub ConvertPdfToTiff_DocumentConverter(pdfFileName As String, tiffFileName As String)
        Vintasoft.Imaging.DocumentConverter.Convert(pdfFileName, tiffFileName)
    End Sub
    


    Here is C#/VB.NET code that shows how to convert PDF document with specified resolution to TIFF file using DocumentConverter class:
    /// <summary>
    /// Converts PDF document to TIFF file using Vintasoft.Imaging.DocumentConverter class.
    /// PDF document is rendered with specified resolution.
    /// </summary>
    public static void ConvertPdfToTiff_CustomResolution_DocumentConverter(string pdfFileName, string tiffFileName)
    {
        // create the document convertor
        Vintasoft.Imaging.DocumentConverter converter = new Vintasoft.Imaging.DocumentConverter();
        // subscribe to the DocumentConverter.ImageDecodingStarting event
        converter.ImageDecodingStarting += Converter_ImageDecodingStarting;
        // add PDF pages to the document convertor
        converter.Images.Add(pdfFileName);
        // convert PDF pages to TIFF images
        converter.Convert(tiffFileName);
    }
    
    /// <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 file resolution
            e.RenderingSettings.Resolution = new Vintasoft.Imaging.Resolution(128, 128);
        }
    }
    
    ''' <summary>
    ''' Converts PDF document to TIFF file using Vintasoft.Imaging.DocumentConverter class.
    ''' PDF document is rendered with specified resolution.
    ''' </summary>
    Public Shared Sub ConvertPdfToTiff_CustomResolution_DocumentConverter(pdfFileName 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
        ' add PDF pages to the document convertor
        converter.Images.Add(pdfFileName)
        ' convert PDF pages to TIFF images
        converter.Convert(tiffFileName)
    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 file resolution
            e.RenderingSettings.Resolution = New Vintasoft.Imaging.Resolution(128, 128)
        End If
    End Sub
    


    Here is C#/VB.NET code that shows how to convert PDF document with default resolution (96 dpi) to TIFF file using ImageCollection class:
    /// <summary>
    /// Converts PDF document to TIFF file using ImageCollection and TiffEncoder classes.
    /// </summary>
    public static void ConvertPdfToTiff_ImageCollection(string pdfFileName, string tiffFileName)
    {
        // create image collection
        using (Vintasoft.Imaging.ImageCollection imageCollection = 
            new Vintasoft.Imaging.ImageCollection())
        {
            // add PDF document to collection
            imageCollection.Add(pdfFileName);
    
            // create TiffEncoder
            using (Vintasoft.Imaging.Codecs.Encoders.TiffEncoder tiffEncoder = 
                new Vintasoft.Imaging.Codecs.Encoders.TiffEncoder(true))
            {
                // set TIFF compression to Zip
                tiffEncoder.Settings.Compression = 
                    Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffCompression.Zip;
    
                // save images of image collection to TIFF file using TiffEncoder
                imageCollection.SaveSync(tiffFileName, tiffEncoder);
            }
    
            // dispose images
            imageCollection.ClearAndDisposeItems();
        }
    }
    
    ''' <summary>
    ''' Converts PDF document to TIFF file using ImageCollection and TiffEncoder classes.
    ''' </summary>
    Public Shared Sub ConvertPdfToTiff_ImageCollection(pdfFileName As String, tiffFileName As String)
        ' create image collection
        Using imageCollection As New Vintasoft.Imaging.ImageCollection()
            ' add PDF document to collection
            imageCollection.Add(pdfFileName)
    
            ' create TiffEncoder
            Using tiffEncoder As New Vintasoft.Imaging.Codecs.Encoders.TiffEncoder(True)
                ' set TIFF compression to Zip
                tiffEncoder.Settings.Compression = Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffCompression.Zip
    
                ' save images of image collection to TIFF file using TiffEncoder
                imageCollection.SaveSync(tiffFileName, tiffEncoder)
            End Using
    
            ' dispose images
            imageCollection.ClearAndDisposeItems()
        End Using
    End Sub
    


    Here is C#/VB.NET code that shows how to convert PDF document with specified resolution to TIFF file using ImageCollection class:
    /// <summary>
    /// Converts PDF document to TIFF file using ImageCollection and TiffEncoder classes.
    /// PDF document is rendered with specified resolution.
    /// </summary>
    public static void ConvertPdfToTiffU_CustomResolution_ImageCollection(string pdfFileName, string tiffFileName, float dpi)
    {
        // create image collection
        using (Vintasoft.Imaging.ImageCollection imageCollection = new Vintasoft.Imaging.ImageCollection())
        {
            // add PDF document to collection
            imageCollection.Add(pdfFileName);
    
            // set rendering settings
            imageCollection.SetRenderingSettings(new Vintasoft.Imaging.Codecs.Decoders.RenderingSettings(
                dpi,
                dpi,
                Vintasoft.Imaging.ImageInterpolationMode.HighQualityBilinear,
                Vintasoft.Imaging.Drawing.DrawingSmoothingMode.AntiAlias));
    
            // create TiffEncoder
            using (Vintasoft.Imaging.Codecs.Encoders.TiffEncoder tiffEncoder = 
                new Vintasoft.Imaging.Codecs.Encoders.TiffEncoder(true))
            {
                // set TIFF compression to Zip
                tiffEncoder.Settings.Compression = 
                    Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffCompression.Zip;
    
                // save images of image collection to TIFF file using TiffEncoder
                imageCollection.SaveSync(tiffFileName, tiffEncoder);
            }
    
            // dispose images
            imageCollection.ClearAndDisposeItems();
        }
    }
    
    ''' <summary>
    ''' Converts PDF document to TIFF file using ImageCollection and TiffEncoder classes.
    ''' PDF document is rendered with specified resolution.
    ''' </summary>
    Public Shared Sub ConvertPdfToTiffU_CustomResolution_ImageCollection(pdfFileName As String, tiffFileName As String, dpi As Single)
        ' create image collection
        Using imageCollection As New Vintasoft.Imaging.ImageCollection()
            ' add PDF document to collection
            imageCollection.Add(pdfFileName)
    
            ' set rendering settings
            imageCollection.SetRenderingSettings(New Vintasoft.Imaging.Codecs.Decoders.RenderingSettings(dpi, dpi, Vintasoft.Imaging.ImageInterpolationMode.HighQualityBilinear, Vintasoft.Imaging.Drawing.DrawingSmoothingMode.AntiAlias))
    
            ' create TiffEncoder
            Using tiffEncoder As New Vintasoft.Imaging.Codecs.Encoders.TiffEncoder(True)
                ' set TIFF compression to Zip
                tiffEncoder.Settings.Compression = Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffCompression.Zip
    
                ' save images of image collection to TIFF file using TiffEncoder
                imageCollection.SaveSync(tiffFileName, tiffEncoder)
            End Using
    
            ' dispose images
            imageCollection.ClearAndDisposeItems()
        End Using
    End Sub
    


    Here is C#/VB.NET code that shows how to convert PDF document with default resolution (96 dpi) to TIFF file using PdfDocument and TiffFile classes:
    /// <summary>
    /// Converts PDF document to TIFF file using PdfDocument and TiffFile classes.
    /// </summary>
    public static void ConvertPdfToTiff_TiffFile(string pdfFileName, string tiffFileName)
    {
        // open existing PDF document
        using (Vintasoft.Imaging.Pdf.PdfDocument pdfDocument = new Vintasoft.Imaging.Pdf.PdfDocument(pdfFileName))
        {
            // create new TIFF file
            using (Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffFile tiffFile = 
                new Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffFile(tiffFileName, 
                    Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffFileFormat.LittleEndian))
            {
                // set TIFF compression to Zip
                tiffFile.Pages.EncoderSettings.Compression = 
                    Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffCompression.Zip;
                // for each PDF page
                for (int i = 0; i < pdfDocument.Pages.Count; i++)
                {
                    // render PDF page and add as image to Tiff file
                    tiffFile.Pages.Add(pdfDocument.Pages[i].Render());
                    // save changes to TIFF file
                    tiffFile.SaveChanges();
                }
            }
        }
    }
    
    ''' <summary>
    ''' Converts PDF document to TIFF file using PdfDocument and TiffFile classes.
    ''' </summary>
    Public Shared Sub ConvertPdfToTiff_TiffFile(pdfFileName As String, tiffFileName As String)
        ' open existing PDF document
        Using pdfDocument As New Vintasoft.Imaging.Pdf.PdfDocument(pdfFileName)
            ' create new TIFF file
            Using tiffFile As New Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffFile(tiffFileName, Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffFileFormat.LittleEndian)
                ' set TIFF compression to Zip
                tiffFile.Pages.EncoderSettings.Compression = Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffCompression.Zip
                ' for each PDF page
                For i As Integer = 0 To pdfDocument.Pages.Count - 1
                    ' render PDF page and add as image to Tiff file
                    tiffFile.Pages.Add(pdfDocument.Pages(i).Render())
                    ' save changes to TIFF file
                    tiffFile.SaveChanges()
                Next
            End Using
        End Using
    End Sub
    


    Here is C#/VB.NET code that shows how to convert PDF document with specified resolution to TIFF file using PdfDocument and TiffFile classes:
    /// <summary>
    /// Converts PDF document to TIFF file using PdfDocument and TiffFile classes.
    /// PDF document is rendered with specified resolution.
    /// </summary>
    public static void ConvertPdfToTiff_CustomResolution_TiffFile(string pdfFileName, string tiffFileName, float dpi)
    {
        // open existing PDF document
        using (Vintasoft.Imaging.Pdf.PdfDocument pdfDocument = 
            new Vintasoft.Imaging.Pdf.PdfDocument(pdfFileName))
        {
            // set resolution
            pdfDocument.RenderingSettings.Resolution = 
                new Vintasoft.Imaging.Resolution(dpi, dpi);
            
            // set rendering mode - optimal balance between rendering speed and quality
            pdfDocument.RenderingSettings.RenderingMode = Vintasoft.Imaging.Pdf.PdfRenderingMode.Normal;
    
            // create new TIFF file
            using (Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffFile tiffFile = 
                new Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffFile(tiffFileName, 
                    Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffFileFormat.LittleEndian))
            {
                // set TIFF compression to Zip
                tiffFile.Pages.EncoderSettings.Compression = 
                    Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffCompression.Zip;
                // for each PDF page
                for (int i = 0; i < pdfDocument.Pages.Count; i++)
                {
                    // render PDF page and add as image to Tiff file
                    tiffFile.Pages.Add(pdfDocument.Pages[i].Render());
                    // save changes to TIFF file
                    tiffFile.SaveChanges();
                }
            }
        }
    }
    
    ''' <summary>
    ''' Converts PDF document to TIFF file using PdfDocument and TiffFile classes.
    ''' PDF document is rendered with specified resolution.
    ''' </summary>
    Public Shared Sub ConvertPdfToTiff_CustomResolution_TiffFile(pdfFileName As String, tiffFileName As String, dpi As Single)
        ' open existing PDF document
        Using pdfDocument As New Vintasoft.Imaging.Pdf.PdfDocument(pdfFileName)
            ' set resolution
            pdfDocument.RenderingSettings.Resolution = New Vintasoft.Imaging.Resolution(dpi, dpi)
    
            ' set rendering mode - optimal balance between rendering speed and quality
            pdfDocument.RenderingSettings.RenderingMode = Vintasoft.Imaging.Pdf.PdfRenderingMode.Normal
    
            ' create new TIFF file
            Using tiffFile As New Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffFile(tiffFileName, Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffFileFormat.LittleEndian)
                ' set TIFF compression to Zip
                tiffFile.Pages.EncoderSettings.Compression = Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffCompression.Zip
                ' for each PDF page
                For i As Integer = 0 To pdfDocument.Pages.Count - 1
                    ' render PDF page and add as image to Tiff file
                    tiffFile.Pages.Add(pdfDocument.Pages(i).Render())
                    ' save changes to TIFF file
                    tiffFile.SaveChanges()
                Next
            End Using
        End Using
    End Sub