VintaSoft Barcode .NET SDK 14.3: Documentation for .NET developer
Vintasoft.Barcode Namespace / PdfImageViewer Class
Members Object Syntax Remarks Example Hierarchy Requirements SeeAlso
In This Topic
    PdfImageViewer Class
    In This Topic
    Class that allows to retrieve image-resources from PDF document.
    Object Model
    PdfImageViewer
    Syntax
    'Declaration
    
    Public NotInheritable Class PdfImageViewer
    
    
    public sealed class PdfImageViewer
    
    
    public __gc __sealed class PdfImageViewer
    
    
    public ref class PdfImageViewer sealed
    
    
    Remarks

    Supported compressions of image-resource:

    • ZIP
    • JPEG (only for DeviceGray and DeviceRGB color space)
    • CCITT3
    • CCITT4
    • LZW
    • Run Length

    Supported color spaces of image-resource:
    • DeviceGray
    • DeviceRGB
    • DeviceCMYK
    • Indexed
    Supported bits per component of image-resource:
    • 1
    • 8

    Example

       
       
    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));
                            }
                        }
                    }
                }
            }
        }
    }
    
    

    Inheritance Hierarchy

    System.Object
       Vintasoft.Barcode.PdfImageViewer

    Requirements

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

    See Also