Providing the full spectrum of document, content, & imaging solutions
Barcode Xpress version 7 released

View White Paper as PDF

Product used in this white paper
Barcode Xpress - barcode SDK for 1D and 2D barcode recognition and creation

Download Barcode Xpress


Sample Code 39 Extended Barcode

Barcodes are a common sight on consumer products. Almost every retail transaction in North America is driven by the scanning, recognition and lookup of barcode data. But did you know you can also add barcodes to the forms your organization creates? Doing so gives the scanned image a readily identifiable key (a patient, client or customer id), which allows for easy storage and retrieval in a database or content management system. Using a barcode to associate a scanned image with a unique key is called automatic indexing (or "auto-indexing") of documents. Auto-indexing is enabled by an easy to use, read-write Barcode SDK, such as
Barcode Xpress from Accusoft.

In Barcode Xpress, adding barcode creation and recognition can be done in just a few lines of code. Here are a few use cases showing practical application.


Use Case: Medical Patient Registration Form

Let's consider a simple application: patient registration forms for a doctor's office. The forms are pre-printed, with explanatory text and a space for the patient's name, date and signature. Add a barcode to the top of this page which contains the patient's id and name and when the form is scanned, it can be automatically attached to the patient's electronic record.

In this example, we will use a 2D barcode to maximize the amount of information which can be stored. Barcode Xpress supports writing of the 2D DataMatrix and PDF417 formats, both of which have compact footprints, which allow them to be easily integrated into the existing whitespace on a form. We'll print the patient's name and ID, separated by a colon, about 5/8 of an inch inset from the top and left hand edges of the pre-printed form. Next, encode the patient's name ("Scott Wilson") along with an ID ("2011-0123456789-01-234-5678") with a colon separating the two fields. This produces a DataMatrix barcode that looks like this:

2D Datamatrix Barcode

Here's the C# code that produces this barcode image using the Barcode Xpress SDK:

- Hide Listing 1: Write a DataMatrix Barcode

class Program
{
	static void Main(string[] args)
	{
		// These would come out of a database

		String patientName = "Scott Wilson";
		String patientId = "2011-0123456789-01-234-5678";
	
		PrintPatientCode(patientName, patientId);
	}
	
	static void PrintPatientCode(String patientName, String patientId)
	{
		// create and unlock the BarcodeXpress component
		BarcodeXpress bcx = new BarcodeXpress();
		bcx.Licensing.UnlockRuntime(12345, 12345, 12345, 12345);
		
		ImagXpress ix = new ImagXpress();
		
		WriterDataMatrix dataMatrix = new WriterDataMatrix(bcx);
		// Set the text value

		dataMatrix.BarcodeValue = patientName + ":" + patientId;
		// call Create and get resulting image
		ImageX img = Accusoft.ImagXpressSdk.ImageX.FromHdib(id, dataMatrix.Create());
		
		// Create an instance of our printer class
		PCPrint printer = new PCPrint();
		printer.bitmapToPrint = img.ToBitmap(false);
		// Issue print command

		printer.Print();
	}
}

public class PCPrint : System.Drawing.Printing.PrintDocument
{
	public Bitmap bitmapToPrint;
	
	protected override void OnPrintPage(System.Drawing.Printing.PrintPageEventArgs e)
	{
		// Run base code

		base.OnPrintPage(e);
		
		// Position the bitmap on the page
		e.Graphics.DrawImage(bitmapToPrint, new RectangleF(36, 36, 72, 72));
	}
}

This produces a form with the 2D Datamatrix barcode in the top left. When printed on the patient information form, it looks like this:

Patient Barcode Form

For redundancy, some customers add the barcode in two places (on the top left and bottom right of the form or document, for example). This will assist in recognition if the form is damaged. Adding redundant barcodes can be done by simply making another call to DrawImage().

Recognizing this image in a scanned document is a snap with the easy to use Barcode Xpress SDK. The form shown above was scanned on a Ricoh Aficio MP C4500 Multifunction printer into a TIF file.

We can process this image and extract the barcode as follows:

- Hide Listing 2: Read a DataMatrix Barcode

class Program

{
	static void Main(string[] args)
	{
		// create and unlock the BarcodeXpress component
		BarcodeXpress bcx = new BarcodeXpress();
		bcx.Licensing.UnlockRuntime(12345, 12345, 12345, 12345);
		
		// load a 1BPP, black and white image into the ImageXpressT control
		ImagXpress ix = new ImagXpress();
		String filename = "C:\\Temp\\legal.tif"; // this would be a parameter
		ImageX imagex = Accusoft.ImageXpressSdk.ImageX.FromFile(ix, filename);
		
		// set barcode types to search for

		System.Array currentBarcodeTypes = new BarcodeType[1];
		currentBarcodeTypes.SetValue(BarcodeType.DataMatrixBarcode, 0);
		bcx.reader.BarcodeTypes = currentBarcodeTypes;
		
		// call AnalyzeBarcode to detect barcodes in image
		// all detected barcodes result, will be returned to the Result object array.
		Accusoft.BarcodeXpressSdk.Result[] results = bcx.reader.Analyze(imagex.ToHdib(false));
		
		// get some results into, if any

		for (short i = 0; i < results.Length; i++)
		{
			// get result for current barcode
			Accusoft.BarcodeXpressSdk.Result curResult = (Accusoft.BarcodeXpressSdk.Result)results.GetValue(i);
			Console.WriteLine("Value is " + curResult.BarcodeValue);
			Console.ReadLine();
			
			// At this point, update the database to parse the id

			// out of curResult.BarcodeValue,
			// and associate it with the file in filename
		}
		
		// dispose of the created components
		ix.Dispose();
		bcx.Dispose();
	}
}

When run, this program will output the expected patient information:

Value is Scott Wilson:2011-0123456789-01-234-5678


Use Case: Payment Agreement for Legal Services

This time let's use a PDF417 barcode, and place it at the top of the page in the center. The number of changes needed is very small. Instead of creating a WriterDataMatrix, we'll create a WriterPDF417 and change the position used in the DrawImage call. Finally, when reading the image, the BarCodeTypes array will be set to only look for PDF417.

Here's the C# code to create the image:

- Hide Listing 3: Write a PDF417 Barcode

class Program
{
	static void Main(string[] args)
	{
		// These would come out of a database

		String patientName = "Scott Wilson";
		String patientId = "2011-0123456789-01-234-5678";
	
		PrintPatientCode(patientName, patientId);
	}
	
	static void PrintPatientCode(String patientName, String patientId)
	{
		// create and unlock the BarcodeXpress component

		BarcodeXpress bcx = new BarcodeXpress();
		bcx.Licensing.UnlockRuntime(12345, 12345, 12345, 12345);
		
		ImagXpress ix = new ImagXpress();
		
		WriterPDF417 pdf417 = new WriterPDF417(bcx);
		// Set the text value

		pdf417.BarcodeValue = clientName + ":" + clientId;
		// call Create and get result image
		ImageX img = Accusoft.ImagXpressSdk.ImageX.FromHdib(ix, pdf417.Create());
		
		// Create an instance of our printer class
		PCPrint printer = new PCPrint();
		printer.bitmapToPrint = img.ToBitmap(false);
		// Issue print command

		printer.Print();
		
		// dispose of the created components
		ix.Dispose();
		bcx.Dispose();
	}
}

public class PCPrint : System.Drawing.Printing.PrintDocument
{
	public Bitmap bitmapToPrint;
	
	protected override void OnPrintPage(System.Drawing.Printing.PrintPageEventArgs e)
	{
		// Run base code

		base.OnPrintPage(e);
		
		// Position the bitmap on the page
		e.Graphics.DrawImage(bitmapToPrint, new Rectangle(72*3, 0, 72*5, 72*2));
	}
}

And here is the C# code to read it back out:

- Hide Listing 4: Read a PDF417 Barcode

class Program
{
	static void Main(string[] args)
	{
		// create and unlock the BarcodeXpress component
		BarcodeXpress bcx = new BarcodeXpress();
		bcx.Licensing.UnlockRuntime(12345, 12345, 12345, 12345);
		
		// load a 1BPP, black and white image into the ImageXpressT control

		ImagXpress ix = new ImagXpress();
		String filename = "C:\\Temp\\legal.tif"; // this would be a parameter
		ImageX imagex = Accusoft.ImageXpressSdk.ImageX.FromFile(ix, filename);
		
		// set barcode types to search for

		System.Array currentBarcodeTypes = new BarcodeType[1];
		currentBarcodeTypes.SetValue(BarcodeType.PDF417Barcode, 0);
		bcx.reader.BarcodeTypes = currentBarcodeTypes;
		
		// call AnalyzeBarcode to detect barcodes in image
		// all detected barcodes result, will be returned to the Result object array.
		Accusoft.BarcodeXpressSdk.Result[] results = bcx.reader.Analyze(imagex.ToHdib(false));
		
		// get some results into, if any

		for (short i = 0; i < results.Length; i++)
		{
			// get result for current barcode
			Accusoft.BarcodeXpressSdk.Result curResult = (Accusoft.BarcodeXpressSdk.Result)results.GetValue(i);
			Console.WriteLine("Value is " + curResult.BarcodeValue);
			Console.ReadLine();
			
			// At this point, update the database to parse the id

			// out of curResult.BarcodeValue,
			// and associate it with the file in filename
		}
		
		// dispose of the created components
		ix.Dispose();
		bcx.Dispose();
	}
}

The printed page will now look like this:

Legal Services Agreement Barcode Sample


Other Use Cases

We have just demonstrated two possibilities, but there are many others:

  • Real estate and property transaction forms
  • State and local government forms
  • Delivery receipts
  • Parental permission slips for schools

The possibilities for using barcodes on your forms are endless!


Conclusion

Barcode recognition is the most efficient way to facilitate the auto-indexing of documents, associating form images with a patient, client or account id. Third-party SDKs like Barcode Xpress from Accusoft make it very easy to perform this task.

Find out more about the Barcode Xpress product features and download an unlimited trial version at www.accusoft.com/barcodexpress.htm. Try your own images on our latest web demo at http://demos.accusoft.com/barcodexpressdemo/. Please contact us at info@accusoft.com for more information.

About the Author

Scott Wilson is a Project Manager with Accusoft. He has had over 20 years of software development and management experience. Scott graduated with a B.Sc. from McMaster University in Hamilton, Canada.

About Accusoft

Accusoft provides a full spectrum of document, content and imaging solutions. With its broad range of solutions, Accusoft is committed to deliver best-in-class, enterprise grade and fully-supported applications and a globally recognized suite of software development kits (SDKs). Accusoft products work reliably behind the scenes for capturing, processing, storing and viewing images, documents and more. Add barcode, compression, DICOM, image processing, OCR/ICR, forms processing, PDF, scanning, video, and image viewing to your applications. Products are delivered as applications and toolkits for multiple 32-bit/64-bit platforms and development environments, including iOS, Android, .NET, Silverlight, ASP.NET, ActiveX, Java, Linux, Solaris, Mac OSX, and IBM AIX. For more information, please visit www.accusoft.com.