We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How can we read barcode using Syncfusion

Hi,

We have a requirement where we need to read the bar code from a PDF file. Can we do it using Syncfusion? If yes, then could you please provide me the code snippet for that ?

I have come across examples for generating the bar code, but none for reading it. So kindly help me with this.

Thanks in advance.

Regards,
Swati

3 Replies

CM Chinnu Muniyappan Syncfusion Team October 26, 2016 09:26 AM UTC

Hi Swati, 
 
Thank you for contacting Syncfusion support. 
 
Currently we don’t have support for reading barcodes in Universal Windows platform, however we have created a workaround sample for achieving your requirement. Here we have using Syncfusion.SfPdfViewerControl to export PDF page to image and scan the image to Zxing barcode scanner. Please refer the below code snippet and sample for more details. 
 
            
            //Initialize PDF viewer control 
            SfPdfViewerControl control = new SfPdfViewerControl(); 
 
            //Load the PDF document 
            await control.LoadDocumentAsync(docStream); 
 
            //Export the page as image 
            Stream imgStream = await control.ExportAsImage(0); 
            
            imgStream.Position = 0; 
 
            //Get the image RGB data 
            var BitmapImageDecoder = await BitmapDecoder.CreateAsync(imgStream.AsRandomAccessStream()); 
 
            PixelDataProvider provider = await BitmapImageDecoder.GetPixelDataAsync().AsTask().ConfigureAwait(false); 
            var imageData = provider.DetachPixelData(); 
 
            //initialize the ZXing barcode reader 
            ZXing.BarcodeReader reader = new ZXing.BarcodeReader(); 
 
            //Reader the barcode 
            ZXing.Result[] results = reader.DecodeMultiple(imageData, (int)BitmapImageDecoder.PixelWidth, (int)BitmapImageDecoder.PixelHeight, ZXing.RGBLuminanceSource.BitmapFormat.Unknown); 
 
 
Sample link: 
Note: Run the following command in the Package Manager Console to install the ZXing.Net.Mobile barcode scanner. 
Install-Package ZXing.Net.Mobile 
Please let us know if you need any further assistance. 
Regards, 
Chinnu 



BH Bhalchandra July 27, 2017 12:34 PM UTC

i have requirement  to read the bar code from a Image file. please guide me




CM Chinnu Muniyappan Syncfusion Team July 28, 2017 12:25 PM UTC

Hi Bhalchandra, 

Thank you for contacting Syncfusion support. 

As we said earlier, currently we don’t have barcode reader support in UWP platform. So, we have suggested you, to use Zxing barcode scanner API for reading barcode from an image. Please refer the below code snippet and sample for more details. 

             
            //Load the image from the embbeded resource. 
            Stream imgStream = typeof(MainPage).GetTypeInfo().Assembly.GetManifestResourceStream("BarcodeReader.Assets.Barcode.png"); 
                  
            //Set the image stream position.      
            imgStream.Position = 0; 
 
            //Get the image RGB data. 
            var BitmapImageDecoder = await BitmapDecoder.CreateAsync(imgStream.AsRandomAccessStream()); 
 
           PixelDataProvider provider = await BitmapImageDecoder.GetPixelDataAsync().AsTask().ConfigureAwait(false); 
            var imageData = provider.DetachPixelData(); 
 
            //initialize the ZXing barcode reader 
            ZXing.BarcodeReader reader = new ZXing.BarcodeReader(); 
 
            //Reader the barcode 
            ZXing.Result[] results = reader.DecodeMultiple(imageData, (int)BitmapImageDecoder.PixelWidth, (int)BitmapImageDecoder.PixelHeight, ZXing.RGBLuminanceSource.BitmapFormat.Unknown); 



Please let us know if you have any concern. 

Regards, 
Chinnu 


Loader.
Up arrow icon