Reading Bangladeshi NID and Smart Cards with ZXing

Bangladeshi NID and Smart Cards come printed with a 2D Datamatrix Barcode, known as PDF417. The information on the cards can be extracted without using an OCR solution through the barcode. We’ll be using Google’s ZXing library; learn about the basics of using it.

Mishandling of data or forgery of cards are treated as punishable offences around the world, including Bangladesh. Please consider legal consequences before proceeding. The reader is solely responsible for any legal consequences.



Let’s add them to Gradle.

dependencies {
    compile ''
    compile ''

A Basic Scan

Pretty self-explanatory. You can build a BufferedImage from any InputStream, a file, a web request or socket connection and so on.

import java.awt.image.BufferedImage;

public class IDScanner {
    public static String processImage(BufferedImage image) throws ReaderException {
        LuminanceSource source = new BufferedImageLuminanceSource(image);
        PDF417Reader reader = new PDF417Reader();

        BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
        Result result = reader.decode(bitmap);
        return result.getText();


The rest is just parsing the resulting text and grabbing the results. I suggest reading through the source code of for a better understanding.

Parsing NID

The format is pretty simple and straightforward. It looks kind of like XML. (I added line breaks for better visibility, there are no line-breaks in reality)

<name>HELLO WORLD</name>
<DOB>01 Jan 1970</DOB>
  • pin: NID Number
  • name: Name
  • DOB: Date of Birth (dd MMM yyyy)
  • FP: Fingerprint in FMR format (Binary)
  • rnd: No idea (Binary)
  • ds: No idea (Binary)

Parsing Smart Card

It is a bit different. No XML here! (There are no line-breaks, actually there are spaces where I put line-breaks)

  • NM: Name
  • HW: Smart Card Number
  • OL: Old NID Card Number
  • BR: Birthdate
  • PE: No idea
  • PR: No idea
  • VA: No idea
  • DT: Date of Issue (Probably)


Our NID and smart cards are great tools to automatically and manually validate identity for legitimate purposes. Please ensure great care and security for safeguarding the information of your customers. Do not overlook legal advice before implementing such a system on your premises.

8 replies on “Reading Bangladeshi NID and Smart Cards with ZXing”

PE: Permanent Address [first two digit district code, second two police station code]
PR: Present Address [first two digit district code, second two police station code]
VA: Voter Area [Unique voter area code of four digits]

Brother I have a solution which was developed by Java , Open CV and Googles’s Tresseract. This is basically a OCR solution which can take bengali and english information from bangladeshi old NID and new smart card.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.