VintaSoft Barcode .NET SDK v10.0
Vintasoft.WpfBarcode Namespace / PdfImageViewer Class
Members Example




In This Topic
    PdfImageViewer Class
    In This Topic
    Class that allows to retrieve image resources from the PDF document.
    Object Model
    PdfImageViewer Class
    Syntax
    'Declaration
     
    <LicenseProviderAttribute(Vintasoft.WpfBarcode.VintasoftLicenseProvider)>
    Public NotInheritable Class PdfImageViewer 
    'Usage
     
    Dim instance As PdfImageViewer
    [LicenseProvider(Vintasoft.WpfBarcode.VintasoftLicenseProvider)]
    public sealed class PdfImageViewer 
    [LicenseProvider(Vintasoft.WpfBarcode.VintasoftLicenseProvider)]
    public __gc __sealed class PdfImageViewer 
    [LicenseProvider(Vintasoft.WpfBarcode.VintasoftLicenseProvider)]
    public ref class PdfImageViewer sealed 
    Remarks
    Supported compressions:
    • ZIP
    • JPEG (only for DeviceGray and DeviceRGB color space)
    • CCITT3
    • CCITT4
    • LZW
    • Run Length

    Supported color spaces:
    • DeviceGray
    • DeviceRGB
    • DeviceCMYK
    • Indexed
    Example
    Imports System.Windows.Media.Imaging   
       
    Imports Vintasoft.WpfBarcode   
       
    ''' <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 BitmapSource   
    						' 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)   
       
    						' 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 System.Windows.Media.Imaging;
                
    using Vintasoft.WpfBarcode;
                
    /// <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]));
                            BitmapSource 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);
                
                            // 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.WpfBarcode.PdfImageViewer

    Requirements

    Target Platforms: Windows 8, Windows 7, Windows Vista, Windows XP, Windows Server 2012, Windows Server 2008, Windows Server 2003

    See Also