VintaSoft Imaging .NET SDK 14.0: Документация для .NET разработчика
В этом разделе
    Кодеки: Как преобразовать PDF в TIFF?
    В этом разделе
    VintaSoft Imaging .NET SDK рендерить PDF страницу (рисует текст, изображения и графику на PDF странице) при преобразовании PDF документа в TIFF файл.

    По умолчанию SDK:
    Вам необходимо переопределить алгоритм поиска внешних шрифтов, если PDF документ содержит нестандартные внешние шрифты. Это можно сделать с помощью класса FileFontProgramsControllerWithFallbackFont.
    Более подробную информацию о шрифтах в PDF документе можно найти здесь .

    VintaSoft Imaging .NET SDK позволяет конвертировать PDF документ в TIFF файл, используя класс DocumentConverter, ImageCollection или TiffFile. Использование класса DocumentConverter обеспечивает наилучшую производительность, поскольку класс DocumentConverter использует многопоточность.


    Вот C#/VB.NET код, который демонстрирует, как сконвертировать PDF документ с разрешением по умолчанию (96 точек на дюйм) в TIFF файл с помощью класса DocumentConverter:
    /// <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
    


    Вот C#/VB.NET код, который демонстрирует, как преобразовать PDF документ с указанным разрешением в TIFF файл с помощью класса DocumentConverter:
    /// <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
    


    Вот C#/VB.NET код, который демонстрирует, как преобразовать PDF документ с разрешением по умолчанию (96 точек на дюйм) в TIFF файл с использованием класса ImageCollection:
    /// <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
    


    Вот C#/VB.NET код, который демонстрирует, как преобразовать PDF документ с указанным разрешением в TIFF файл с использованием класса ImageCollection:
    /// <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
    


    Вот C#/VB.NET код, который демонстрирует, как преобразовать PDF документ с разрешением по умолчанию (96 точек на дюйм) в TIFF файл с использованием классов PdfDocument и TiffFile:
    /// <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
    


    Вот C#/VB.NET код, который демонстрирует, как преобразовать PDF документ с указанным разрешением в TIFF файл с помощью классов PdfDocument и TiffFile:
    /// <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