VintaSoft Barcode .NET SDK 15.0: Руководство для .NET разработчика
Vintasoft.Barcode Namespace / PdfImageViewer Class
    Класс PdfImageViewer
    В этом разделе
    Класс, который позволяет извлекать изображения-ресурсы из PDF документа.
    Объектная модель
    PdfImageViewer
    Синтаксис
    'Declaration
    
    Public NotInheritable Class PdfImageViewer
    
    
    public sealed class PdfImageViewer
    
    
    public __gc __sealed class PdfImageViewer
    
    
    public ref class PdfImageViewer sealed
    
    
    Ремарки

    Поддерживаемые способы сжатия изображения-ресурса:

    • ZIP
    • JPEG (только для цветового пространства DeviceGray и DeviceRGB)
    • CCITT3
    • CCITT4
    • LZW
    • Длина тиража

    Поддерживаемые цветовые пространства изображения-ресурса :
    • DeviceGray
    • DeviceRGB
    • DeviceCMYK
    • Indexed
    Поддерживаемые биты на компонент of image-resource:
    • 1
    • 8

    Пример

       
       
    Imports Vintasoft.Imaging   
       
    Imports Vintasoft.Barcode   
       
    ''' <summary>
    ''' Test that shows how to read barcodes from image-resources of PDF document.
    ''' </summary>
    Class PdfImageViewerExample   
        ''' <summary>
        ''' Reads barcodes from image-resources of PDF document.
        ''' </summary>
        Public Shared Sub ReadBarcodesFromPdfDocument(filename As String, barcodeTypes As BarcodeType)   
            ' open PDF document
            Using pdfImageViewer As New PdfImageViewer(filename)   
                ' create the barcode reader
                Using reader As New BarcodeReader()   
                    ' specify that reader must search barcodes of specified type(s)
                    reader.Settings.ScanBarcodeTypes = barcodeTypes   
       
                    ' for each page in PDF document
                    For i As Integer = 0 To pdfImageViewer.PageCount - 1   
                        ' get an array of names of image resources from page i
                        Dim imageNames As String() = pdfImageViewer.GetImageNames(i)   
                        ' for each image resource of page i
                        For k As Integer = 0 To imageNames.Length - 1   
                            Console.WriteLine(String.Format("Page {0}, image {1}: ", i, imageNames(k)))   
                            Dim imageWithBarcode As VintasoftBitmap   
                            ' get image of image resource
                            Try   
                                imageWithBarcode = pdfImageViewer.GetImage(i, imageNames(k))   
                            Catch e As Exception   
                                ' not supported image format
                                Console.WriteLine(e.Message)   
                                Continue For   
                            End Try   
       
                            ' read barcodes from image-resource
                            Dim barcodesInfo As IBarcodeInfo() = reader.ReadBarcodes(imageWithBarcode)   
       
                            ' dispose image
                            imageWithBarcode.Dispose()   
       
                            ' show barcode recognition results
       
                            If barcodesInfo.Length = 0 Then   
                                Console.WriteLine("No barcodes found.")   
                            Else   
                                For j As Integer = 0 To barcodesInfo.Length - 1   
                                    Console.WriteLine(String.Format("[{0}] {1}", barcodesInfo(j).BarcodeType, barcodesInfo(j).Value))   
                                Next   
                            End If   
                        Next   
                    Next   
                End Using   
            End Using   
        End Sub   
    End Class
    
    
    
    using System;
    
    using Vintasoft.Imaging;
    
    using Vintasoft.Barcode;
    
    /// <summary>
    /// Test that shows how to read barcodes from image-resources of PDF document.
    /// </summary>
    class PdfImageViewerExample
    {
        /// <summary>
        /// Reads barcodes from image-resources of PDF document.
        /// </summary>
        public static void ReadBarcodesFromPdfDocument(string filename, BarcodeType barcodeTypes)
        {
            // open PDF document
            using (PdfImageViewer pdfImageViewer = new PdfImageViewer(filename))
            {
                // create the barcode reader
                using (BarcodeReader reader = new BarcodeReader())
                {
                    // specify that reader must search barcodes of specified type(s)
                    reader.Settings.ScanBarcodeTypes = barcodeTypes;
    
                    // for each page in PDF document
                    for (int i = 0; i < pdfImageViewer.PageCount; i++)
                    {
                        // get an array of names of image resources from page i
                        string[] imageNames = pdfImageViewer.GetImageNames(i);
                        // for each image resource of page i
                        for (int k = 0; k < imageNames.Length; k++)
                        {
                            Console.WriteLine(string.Format("Page {0}, image {1}: ", i, imageNames[k]));
                            VintasoftBitmap imageWithBarcode;
                            // get image of image resource
                            try
                            {
                                imageWithBarcode = pdfImageViewer.GetImage(i, imageNames[k]);
                            }
                            catch (Exception e)
                            {
                                // not supported image format
                                Console.WriteLine(e.Message);
                                continue;
                            }
    
                            // read barcodes from image-resource
                            IBarcodeInfo[] barcodesInfo = reader.ReadBarcodes(imageWithBarcode);
    
                            // dispose image
                            imageWithBarcode.Dispose();
    
                            // show barcode recognition results
    
                            if (barcodesInfo.Length == 0)
                            {
                                Console.WriteLine("No barcodes found.");
                            }
                            else
                            {
                                for (int j = 0; j < barcodesInfo.Length; j++)
                                    Console.WriteLine(string.Format("[{0}] {1}",
                                        barcodesInfo[j].BarcodeType, barcodesInfo[j].Value));
                            }
                        }
                    }
                }
            }
        }
    }
    
    

    Иерархия наследования

    System.Object
       Vintasoft.Barcode.PdfImageViewer

    Требования

    Целевые платформы: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

    Смотрите также