Introduction
Because of its accuracy and its ease of use, Barcodes have
become more and more popular as a part of daily document management workflow. You
can use barcodes to identify documents, separate batch scanning, or even get
reliable metadata as a document identifier.
This article will show you how to decode barcodes from an image
captured or scanned in a web application with the help of ImageCapture Suite.
Background
Dynamsoft’s Image
Capture Suite is an online image acquisition
and processing toolkit designed for web applications. It allows you to capture
images from scanners, webcams and other TWAIN/UVC/WIA compatible devices from
all mainstream browsers - Internet Explorer (32-bit/64-bit), Firefox, Chrome
and Safari - on Windows and Mac. The toolkit also comes with a Barcode Reader
SDK which allows you to decode both 1D and 2D barcode symbols online.
If you are interested in the SDK, the 30-day Free Trial can
be downloaded from Dynamsoft website.
Coding Instruction
Special Note
As a component running in the client-side browsers,
JavaScript is the preferred language to call all the methods/properties/events
of ImageCapture Suite
Capture/load the barcode image
ImageCapture Suite allows you to load an existing image or to
capture images from scanners, webcams, etc.
function btnLoad_onclick() {
DWObject.IfShowFileDialog = true; DWObject.LoadImageEx("", 5); }
if(location.hostname != "")
{
DWObject.HTTPPort = location.port == "" ? 80 : location.port;
DWObject.HTTPDownload(location.hostname, location.pathname.substring(0, location.pathname.lastIndexOf('/')) + ImgArr);
}
function AcquireImageInner(){
if (DW_DWTSourceContainerID == "")
DWObject.SelectSource();
else
DWObject.SelectSourceByIndex(document.getElementById(DW_DWTSourceContainerID).selectedIndex);
DWObject.CloseSource();
DWObject.OpenSource();
var iSelectedIndex = document.getElementById(DW_DWTSourceContainerID).selectedIndex;
var iTwainType = DWObject.GetSourceType(iSelectedIndex);
if(iTwainType == 0) {
DWObject.IfShowUI = document.getElementById("ShowUI").checked;
var i;
for(i=0;i<3;i++)
{
if(document.getElementsByName("PixelType").item(i).checked==true)
DWObject.PixelType = i; }
DWObject.Resolution = Resolution.value; DWObject.IfFeederEnabled = document.getElementById("ADF").checked ; DWObject.IfDuplexEnabled = document.getElementById("Duplex").checked ; AppendMessage("Pixel Type: " + DWObject.PixelType + "<br />Resolution: " + DWObject.Resolution + "<br />");
}
Else {
DWObject.IfShowUI = document.getElementById("ShowUIForWebcam").checked;
if (DW_InWindows) {
DWObject.SelectMediaTypeByIndex(document.getElementById("MediaType").selectedIndex);
DWObject.SelectResolutionForCamByIndex(document.getElementById("ResolutionWebcam").selectedIndex);
AppendMessage("MediaType: " + DWObject.MediaType + "<br />Resolution: " + DWObject.ResolutionForCam + "<br />");
}
}
DWObject.IfDisableSourceAfterAcquire = true;
DWObject.AcquireImage(); }
Decode the barcode using JavaScript
After we load or capture a barcode image into the control,
we can then work on decoding the barcode symbols.
function J_Barcoding() {
var barcodeVerStr = DWObject.BarcodeVersion;
if (!barcodeVerStr ||barcodeVerStr != DW_BarcodeVersion) {
if (location.hostname != "") {
var strHostIP = location.hostname;
DWObject.HTTPPort = location.port == "" ? 80 : location.port;
var CurrentPathName = unescape(location.pathname); var CurrentPath = CurrentPathName.substring(0, CurrentPathName.lastIndexOf("/") + 1);
var strBarcodepath = CurrentPath + "Resources/barcode.zip";
DWObject.HTTPDownloadResource(strHostIP, strBarcodepath, "barcode.zip"); }
}
var strLength = DWObject.GetImageSize(DWObject.CurrentImageIndexInBuffer, DWObject.GetImageWidth(DWObject.CurrentImageIndexInBuffer), DWObject.GetImageHeight(DWObject.CurrentImageIndexInBuffer));
if (strLength > 300000) DWObject.IfShowProgressBar = true;
else
DWObject.IfShowProgressBar = false;
var barcodeformat;
barcodeformat = document.getElementById("ddl_barcodeFormat").value; DWObject.ReadBarcode(DWObject.CurrentImageIndexInBuffer, barcodeformat); DWObject.IfShowProgressBar = true;
var barcodeText = "";
barcodeText += "ReadBarcode : " + DWObject.ErrorString + "<br/>";
var count = DWObject.BarcodeCount;
barcodeText += "BarcodeCount: " + count + "<br/>";
for (i = 0; i < count; i++) {
var text = DWObject.GetBarcodeText(i);
var x = DWObject.GetBarcodeInfo(0, i);
var y = DWObject.GetBarcodeInfo(1, i);
var type = DWObject.GetBarcodeInfo(2, i);
var len = DWObject.GetBarcodeInfo(5, i);
barcodeText += ("barcode[" + (i + 1) + "]: " + text + "<br/>");
barcodeText += ("text len:" + len + "<br/>");
barcodeText += ("type:" + getBarcodeType(type) + "<br/>");
barcodeText += ("x: " + x + " y:" + y + "<br/>");
var strBarcodeString = text + "\r\n" + getBarcodeType(type);
DWObject.AddText(DWObject.CurrentImageIndexInBuffer, x, y, strBarcodeString, 255, 4894463, 0, 1);
}
AppendMessage(barcodeText);
J_SetBtnProcessingAndText("btnReadBarcode", false, "Try Barcode");
}
Run or deploy the
application on web server
The complete source code can be downloaded from the article.
There is a "Scripts\ProductKey.js" file with a temporary trial
product key. If you get license error when running the sample, you can download
ImageCapture Suite from Dynamsoft’s website to get a valid
trial license. ImageCapture
Suite 30-Day Free Trial Download
To test barcode reading from different client machines, you can
simply copy the sample code with ImageCapture Suite to your web server (IIS,
Apache or Tomcat). Users only need to download and install the ActiveX/Plugin
in the browser on their first visit to the web page. More details on how
to deploy ImageCaptureSuite
The online demo is also available for your reference.
ImageCapture
Suite Barcode Reader Online Demo