65.9K
CodeProject 正在变化。 阅读更多。
Home

如何使用条形码自动索引扫描的表单

emptyStarIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

0/5 (0投票)

2011 年 2 月 25 日

CPOL

4分钟阅读

viewsIcon

29745

您知道可以向组织使用的表单添加条形码吗? 条形码为扫描的图像提供了一个易于识别的键,从而可以轻松地在数据库或内容管理系统中进行存储和检索。查看代码示例,了解如何将条形码读取和写入添加到应用程序中。

Index-Barcodes/image001.png

条形码在消费品上很常见。北美几乎所有的零售交易都是通过扫描、识别和查找条形码数据来驱动的。但是您知道您也可以将条形码添加到您组织创建的表单中吗?这样做会给扫描的图像提供一个易于识别的键(患者、客户或客户 ID),从而可以轻松地在数据库或内容管理系统中进行存储和检索。使用条形码将扫描的图像与唯一的键关联起来称为文档的自动索引(或“自动编索引”)。自动索引通过易于使用的读写条形码 SDK 实现,例如来自 Accusoft Pegasus 的 Barcode Xpress

在 Barcode Xpress 中,只需几行代码即可添加条形码创建和识别功能。以下是一些用例,展示了实际应用。

用例:医疗患者注册表

让我们考虑一个简单的应用程序:医生办公室的患者注册表。 这些表格是预先打印好的,带有解释性文字以及患者姓名、日期和签名的空间。在页面顶部添加一个条形码,其中包含患者的 ID 和姓名,扫描表单后,它可以自动附加到患者的电子病历中。

在此示例中,我们将使用 2D 条形码来最大化可以存储的信息量。 Barcode Xpress 支持 2D DataMatrix 和 PDF417 格式的写入,这两种格式都具有紧凑的 footprint,这使得它们可以轻松地集成到表单上现有的空白处。我们将患者的姓名和 ID 打印出来,并用冒号分隔,距离预打印表单的顶部和左边缘约 5/8 英寸。接下来,对患者的姓名 ("Scott Wilson") 和 ID ("2011-0123456789-01-234-5678") 进行编码,并用冒号分隔这两个字段。这将生成一个如下所示的 DataMatrix 条形码

Index-Barcodes/image002.png

以下是使用 Barcode Xpress SDK 生成此条形码图像的 C# 代码

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));
	}
}

这将生成一个左上方带有 2D Datamatrix 条形码的表单。 打印在患者信息表上时,它看起来像这样

Index-Barcodes/image004.png

为了冗余,一些客户在两个位置添加条形码(例如,在表单或文档的左上角和右下角)。 如果表单损坏,这将有助于识别。 添加冗余条形码只需再次调用 DrawImage() 即可。

使用易于使用的 Barcode Xpress SDK 可以轻松识别扫描文档中的此图像。 上面显示的表格是在 Ricoh Aficio MP C4500 多功能打印机上扫描到 TIF 文件中的。

我们可以处理此图像并提取条形码,如下所示

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();
	}
}

运行时,此程序将输出预期的患者信息

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

用例:法律服务的付款协议

这次让我们使用 PDF417 条形码,并将其放置在页面顶部的中心。 需要更改的数量非常少。 我们将创建 WriterPDF417 而不是创建 WriterDataMatrix,并更改 DrawImage 调用中使用的位置。 最后,读取图像时,BarCodeTypes 数组将被设置为仅查找 PDF417。

以下是创建图像的 C# 代码

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));
	}
}

以下是将其读回的 C# 代码

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();
	}
}

打印的页面现在看起来像这样

Index-Barcodes/image008.jpg

其他用例

我们刚刚演示了两种可能性,但还有许多其他可能性

  • 房地产和财产交易表格
  • 州和地方政府表格
  • 送货收据

学校的家长许可单

在表单上使用条形码的可能性是无限的!

结论

条形码识别是促进文档自动索引的最有效方式,将表单图像与患者、客户或帐户 ID 相关联。 Accusoft Pegasus 的 Barcode Xpress 等第三方 SDK 使执行此任务非常容易。

了解有关 Barcode Xpress 产品功能的更多信息,并在 http://www.accusoft.com/barcodexpress.htm 下载无限试用版。 在我们的最新网络演示中尝试您自己的图像:http://demos.accusoft.com/barcodexpressdemo/。 如需更多信息,请通过 info@accusoft.com 联系我们。

关于作者

Scott Wilson 是 Accusoft Pegasus 的项目经理。 他拥有超过 20 年的软件开发和管理经验。 Scott 毕业于加拿大汉密尔顿的麦克马斯特大学,获得理学学士学位。

© . All rights reserved.