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 Pegasus.
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:
Here’s the C# code that produces this barcode image using the Barcode Xpress SDK:
class Program
{
static void Main(string[] args)
{
String patientName = "Scott Wilson";
String patientId = "2011-0123456789-01-234-5678";
PrintPatientCode(patientName, patientId);
}
static void PrintPatientCode(String patientName, String patientId)
{
BarcodeXpress bcx = new BarcodeXpress();
bcx.Licensing.UnlockRuntime(12345, 12345, 12345, 12345);
ImagXpress ix = new ImagXpress();
WriterDataMatrix dataMatrix = new WriterDataMatrix(bcx);
dataMatrix.BarcodeValue = patientName + ":" + patientId;
ImageX img = Accusoft.ImagXpressSdk.ImageX.FromHdib(id, dataMatrix.Create());
PCPrint printer = new PCPrint();
printer.bitmapToPrint = img.ToBitmap(false);
printer.Print();
}
}
public class PCPrint : System.Drawing.Printing.PrintDocument
{
public Bitmap bitmapToPrint;
protected override void OnPrintPage(System.Drawing.Printing.PrintPageEventArgs e)
{
base.OnPrintPage(e);
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:
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:
class Program
{
static void Main(string[] args)
{
BarcodeXpress bcx = new BarcodeXpress();
bcx.Licensing.UnlockRuntime(12345, 12345, 12345, 12345);
ImagXpress ix = new ImagXpress();
String filename = "C:\\Temp\\legal.tif"; ImageX imagex = Accusoft.ImageXpressSdk.ImageX.FromFile(ix, filename);
System.Array currentBarcodeTypes = new BarcodeType[1];
currentBarcodeTypes.SetValue(BarcodeType.DataMatrixBarcode, 0);
bcx.reader.BarcodeTypes = currentBarcodeTypes;
Accusoft.BarcodeXpressSdk.Result[] results = bcx.reader.Analyze(imagex.ToHdib(false));
for (short i = 0; i < results.Length; i++)
{
Accusoft.BarcodeXpressSdk.Result curResult = (Accusoft.BarcodeXpressSdk.Result)results.GetValue(i);
Console.WriteLine("Value is " + curResult.BarcodeValue);
Console.ReadLine();
}
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:
class Program
{
static void Main(string[] args)
{
String patientName = "Scott Wilson";
String patientId = "2011-0123456789-01-234-5678";
PrintPatientCode(patientName, patientId);
}
static void PrintPatientCode(String patientName, String patientId)
{
BarcodeXpress bcx = new BarcodeXpress();
bcx.Licensing.UnlockRuntime(12345, 12345, 12345, 12345);
ImagXpress ix = new ImagXpress();
WriterPDF417 pdf417 = new WriterPDF417(bcx);
pdf417.BarcodeValue = clientName + ":" + clientId;
ImageX img = Accusoft.ImagXpressSdk.ImageX.FromHdib(ix, pdf417.Create());
PCPrint printer = new PCPrint();
printer.bitmapToPrint = img.ToBitmap(false);
printer.Print();
ix.Dispose();
bcx.Dispose();
}
}
public class PCPrint : System.Drawing.Printing.PrintDocument
{
public Bitmap bitmapToPrint;
protected override void OnPrintPage(System.Drawing.Printing.PrintPageEventArgs e)
{
base.OnPrintPage(e);
e.Graphics.DrawImage(bitmapToPrint, new Rectangle(72*3, 0, 72*5, 72*2));
}
}
And here is the C# code to read it back out:
class Program
{
static void Main(string[] args)
{
BarcodeXpress bcx = new BarcodeXpress();
bcx.Licensing.UnlockRuntime(12345, 12345, 12345, 12345);
ImagXpress ix = new ImagXpress();
String filename = "C:\\Temp\\legal.tif"; ImageX imagex = Accusoft.ImageXpressSdk.ImageX.FromFile(ix, filename);
System.Array currentBarcodeTypes = new BarcodeType[1];
currentBarcodeTypes.SetValue(BarcodeType.PDF417Barcode, 0);
bcx.reader.BarcodeTypes = currentBarcodeTypes;
Accusoft.BarcodeXpressSdk.Result[] results = bcx.reader.Analyze(imagex.ToHdib(false));
for (short i = 0; i < results.Length; i++)
{
Accusoft.BarcodeXpressSdk.Result curResult = (Accusoft.BarcodeXpressSdk.Result)results.GetValue(i);
Console.WriteLine("Value is " + curResult.BarcodeValue);
Console.ReadLine();
}
ix.Dispose();
bcx.Dispose();
}
}
The printed page will now look like this:
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 Pegasus make it very easy to perform this task.
Find out more about the Barcode Xpress product features and download an unlimited trial version at http://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 Pegasus. He has had over 20 years of software development and management experience. Scott graduated with a B.Sc. from McMaster University in Hamilton, Canada.