12,560,241 members (54,056 online)
alternative version

171.4K views
140 bookmarked
Posted

# Scan and Read the Barcode from PDF File

, 5 Aug 2010 CPOL
 Rate this:
Scan the PDF file and recognize if it contains the Barcode or not

## Acknowledgment

The project is about Barcode recognition. The project contains decode / encode the EAN-13, EAN-8, and QR code barcode. I have also added the functionality to scan the PDF file and the software is smart enough to recognize whether PDF contains any barcode or not.

Detect EAN -13, EAN – 8 and QR code from the PDF file.

## Introduction

We need a functionality that can read the PDF file and recognize the EAN-13 and QR-Code from the file. On top of that, I needed decoding and encoding algorithm of EAN-13 and QR code. I saw some solution on the internet about Barcode Recognition, but they were running somehow a little bit slowly, so I decided to optimize them.

## EAN-13

EAN-13, based upon the UPC-A standard, was implemented by the International Article Numbering Association (EAN) in <place w:st="on">Europe.

A typical EAN-13 bar code looks something like this:

## Computing the Checksum Digit

The steps for calculating the check digit are as follows:

1. Consider the right-most digit of the message to be in an "odd" position, and assign odd/even to each character moving from right to left.
2. Sum the digits in all odd positions, and multiply the result by 3.
3. Sum the digits in all even positions.
4. Sum the totals calculated in steps 2 and 3.
5. The check digit is the number which, when added to the totals calculated in step 4, result in a number evenly divisible by 10.
6. If the sum calculated in step 4 is evenly divisible by 10, the check digit is "0" (not 10).

#### QR Code

A QR Code is a matrix barcode (or two-dimensional code), readable by QR scanners, mobile phones with camera, and smart phones. The code consists of black modules arranged in a square pattern on white background. The information encoded can be text, URL or other data.

## Usage of QR Code

QR codes can store quite complex information in a small matrix. As awareness grows about how useful they are, we can expect to see them in more public venues. Commercial packaging will display codes with detailed nutritional information or links to web­sites where users can play the latest product-associated game or register for updates or coupons. In academic uses, QR codes on student tests could help ensure anonymity in grading. Posted next to artwork or in musical or theatrical programs, QR codes might lead students to open forums where they could join in community discussions about what they've heard or seen. In scientific endeavours, QR codes could take the place of printed labels; attached to lab work, samples, or medication options, they could preserve confidentiality of participant names.

## Using the Code

To open the solution, you'll need Visual Studio 2008.

1. #### EAN -13

To generate the image of EAN-13 barcode, you got to click on the “Encode” button. The attached solution contain “`BarcodeImaging`” project which has the function to draw an image of the entered barcode number.

```//===== Encoding performed here =====

barcode.Image = b.Encode(type, this.txtData.Text.Trim(), W, H);

//===================================```

To decode the EAN -13, go to “EAN-13 Decode” tab where you can select the image file and once you click on Decode button, the software will return the barcode number if image contains a valid barcode.

```//===== Scanning of image performed here =====

BarcodeImaging.FullScanPage(ref barcodes, (Bitmap)this.pictureBox1.Image, iScans);

//===================================```
2. #### QR Code

Enter a data that you want to store into QR code. You can set the encoding, correction level, version and size of the QR Code. Once you click on the Encode button image will be generated.

The attached solution contains the “`QRCodelib`” which has a function of encoding and decoding of the QR Code.

```//===== Encoding performed here =====

String data = txtEncodeData.Text;

image = qrCodeEncoder.Encode(data);

//===================================```

To decode the QR Code:

```//===== Decoding performed here =====

String decodedString = decoder.decode
(new QRCodeBitmapImage(new Bitmap(picDecode.Image)));

//===================================```
3. #### PDF Scan

The most interesting part of this article is to scan the PDF and recognize the barcode. I used “`PdfToImage`” ghost script to generate the images of all the PDF pages. You got to select the PDF file and click on the Scan button, the application will scan the PDF.

## Points of Interest

A person who needs barcode recognition from files can use this project. Apart from existing implemented functionality, I would like some enhancements in the code which are mentioned below:

• Support more barcode symbology
• QR code decoder is running a little bit slow, need optimization on algorithm
• Need more file type support, currently project only supports PDF file
• Need to create EAN-13 code on the basis of country, manufacturing, and product code

## History

This is the first version of my article, I will be posting the second version with enhancements soon.

## Share

 Software Developer (Senior) United States
Piyush has valuable experience in requirements gathering, designing, implementing, and maintaining data-driven, object-oriented and service based enterprise systems. In addition to his technical expertise, Piyush also published paper on knowledge management and he has excellent communication skills to cooperate with the clients.

He holds a Masters Degree in Computer Science from the University Of Michigan, USA

## You may also be interested in...

 First PrevNext
 Can I use those library files on VB.NET and develop? vivianpinto15-May-16 21:23 vivianpinto 15-May-16 21:23
 command line? Member 112038723-Nov-14 20:13 Member 11203872 3-Nov-14 20:13
 PDF not reading barcode Member 1093972714-Aug-14 3:01 Member 10939727 14-Aug-14 3:01
 Re: PDF not reading barcode achilleas229-Oct-14 1:07 achilleas22 9-Oct-14 1:07
 if the bar code not placed correctly Member 107389119-Apr-14 23:51 Member 10738911 9-Apr-14 23:51
 Re: if the bar code not placed correctly Piyush Patell10-Apr-14 6:30 Piyush Patell 10-Apr-14 6:30
 Code 39 barcode Sweta Sansare15-Jan-14 10:35 Sweta Sansare 15-Jan-14 10:35
 gives compile time error Member 1045908812-Dec-13 4:53 Member 10459088 12-Dec-13 4:53
 Re: gives compile time error Piyush Patell26-Dec-13 6:39 Piyush Patell 26-Dec-13 6:39
 Use With VB ziiiiiggg25-Apr-13 3:07 ziiiiiggg 25-Apr-13 3:07
 Re: Use With VB Piyush Patell25-Apr-13 17:30 Piyush Patell 25-Apr-13 17:30
 How improve quality of converision (EAN) Eracle17-Apr-13 5:14 Eracle 17-Apr-13 5:14
 Re: How improve quality of converision (EAN) Piyush Patell25-Apr-13 17:29 Piyush Patell 25-Apr-13 17:29
 gsdll32.dll wasn't found dvr201326-Feb-13 9:29 dvr2013 26-Feb-13 9:29
 Re: gsdll32.dll wasn't found ~Dim~25-Sep-13 22:12 ~Dim~ 25-Sep-13 22:12
 Re: gsdll32.dll wasn't found Brane622-Feb-16 2:45 Brane62 2-Feb-16 2:45
 Integration with VBA Member 98235649-Feb-13 10:57 Member 9823564 9-Feb-13 10:57
 Error when trying to compile it in Visual Studio 2010 Member 34492254-Jan-13 14:21 Member 3449225 4-Jan-13 14:21
 Re: Error when trying to compile it in Visual Studio 2010 ziotullio27-Aug-15 19:46 ziotullio 27-Aug-15 19:46
 EAN13 barcode recognition Member 287984424-Jul-12 1:57 Member 2879844 24-Jul-12 1:57
 Re: EAN13 barcode recognition Piyush Patell25-Jul-12 19:45 Piyush Patell 25-Jul-12 19:45
 EAN 13, work for me can you send me your program along with the files at er.piyushpatel@gmail.com
 Help Needed Member 92266019-Jul-12 5:36 Member 9226601 9-Jul-12 5:36
 Re: Help Needed Piyush Patell9-Jul-12 17:45 Piyush Patell 9-Jul-12 17:45
 barcode reader Zacbr23-Apr-12 13:27 Zacbr 23-Apr-12 13:27
 Re: barcode reader billcook15-May-13 16:10 billcook1 5-May-13 16:10
 Re: barcode reader Piyush Patell5-May-13 20:20 Piyush Patell 5-May-13 20:20
 BarcodeLib.dll Akshay 00719-Mar-12 0:38 Akshay 007 19-Mar-12 0:38
 Re: BarcodeLib.dll Piyush Patell19-Mar-12 1:45 Piyush Patell 19-Mar-12 1:45
 Re: BarcodeLib.dll Akshay 00720-Mar-12 9:25 Akshay 007 20-Mar-12 9:25
 My vote of 5 manoj kumar choubey26-Feb-12 19:40 manoj kumar choubey 26-Feb-12 19:40
 Re: My vote of 5 Piyush Patell5-Mar-12 0:12 Piyush Patell 5-Mar-12 0:12
 PDF417 Support YoungJoe26-Sep-11 5:09 YoungJoe 26-Sep-11 5:09
 Re: PDF417 Support Piyush Patell26-Sep-11 23:55 Piyush Patell 26-Sep-11 23:55
 My vote of 5 v4hid1-May-11 9:10 v4hid 1-May-11 9:10
 Doesnt read skewed or noisy barcodes GPUToaster13-Apr-11 23:50 GPUToaster 13-Apr-11 23:50
 [My vote of 1] Credit where its due. My vote of 1. Member 78136685-Apr-11 8:43 Member 7813668 5-Apr-11 8:43
 Re: [My vote of 1] Credit where its due. My vote of 1. Piyush Patell5-Apr-11 17:43 Piyush Patell 5-Apr-11 17:43
 compile error in sample code? JorisZwaenepoel24-Feb-11 2:14 JorisZwaenepoel 24-Feb-11 2:14
 Re: compile error in sample code? Piyush Patell24-Feb-11 17:56 Piyush Patell 24-Feb-11 17:56
 Re: compile error in sample code? JorisZwaenepoel24-Feb-11 21:07 JorisZwaenepoel 24-Feb-11 21:07
 Re: compile error in sample code? Piyush Patell24-Feb-11 21:17 Piyush Patell 24-Feb-11 21:17
 Re: compile error in sample code? Member 95873969-Nov-12 10:51 Member 9587396 9-Nov-12 10:51
 Re: compile error in sample code? Xavito5-Dec-12 16:57 Xavito 5-Dec-12 16:57
 Other 2D barcode recognized pscorca25-Nov-10 4:10 pscorca 25-Nov-10 4:10
 Re: Other 2D barcode recognized Piyush Patell25-Nov-10 5:44 Piyush Patell 25-Nov-10 5:44
 Re: Other 2D barcode recognized pscorca25-Nov-10 6:09 pscorca 25-Nov-10 6:09
 Re: Other 2D barcode recognized Piyush Patell28-Nov-12 21:20 Piyush Patell 28-Nov-12 21:20