Using Barcode as Batch Separator in Web Application

Mar 14, 2013

For document management, it is a common requirement that a user puts a stack of documents for automatic document feeder (ADF) scanning. The documents may be for different purposes and he wants to save them into different files automatically after the scanning finishes. This way, it will greatly save the time.

So how can we achieve that? How to enable users to do that on your website or with your web application?

Dynamsoft Dynamic Web TWAIN can satisfy your needs well. It is an image acquisition library which enables you to acquire images from TWAIN compatible scanners and USB/WIA compatible webcam, editing the images and upload them to web server, database or other repositories. It comes with a Barcode Reader SDK which supports both 1D & 2D barcode detection.

Dynamic Web TWAIN is a client-side image capture API and you can use JavaScript to call its methods/properties. It has ActiveX, Plugin and HTML5 editions which supports all the main-stream browsers on Windows, including IE (x86/x64), Chrome, Firefox, Safari and Opera.

Online Demo

You can test scanning documents or loading an existing image into the SDK and recognize the barcode online here.

A Simple Sample

Below is a simple sample (HTML/JavaScript + C#) for demonstrating how to use Dynamic Web TWAIN to do ADF batch scanning and save the documents into different PDF files to web server automatically based on barcode separator.

Besides C#, you can also use your preferred server-side language, like PHP, VB.NET, JPS,  for the image upload part.

On client side – Scan.html:

        function ReadBarcode() {
            if (DWObject) {
                if (DWObject.HowManyImagesInBuffer == 0) {
                    alert("Please scan or load an image first.");

                // Call DWObject.Addon.Barcode.Download(url) to download barcode reader module to local.

                //Get barcode result.
                switch (document.getElementById("barcodeformat").selectedIndex) {
                    case 0:
                        result = DWObject.Addon.Barcode.Read(
                            DWObject.CurrentImageIndexInBuffer, EnumDWT_BarcodeFormat.CODE_39);
                            if(result._Count != 0) 
                    case 1:
                        result = DWObject.Addon.Barcode.Read(
                            DWObject.CurrentImageIndexInBuffer, EnumDWT_BarcodeFormat.CODE_128);
                            if(result._Count != 0) 

        function UploadImage() {
            if (DWObject) {
            	  // If no image in buffer, return the function
                if (DWObject.HowManyImagesInBuffer == 0)

                var strHTTPServer = location.hostname; //The name of the HTTP server. For example: "";
                var CurrentPathName = unescape(location.pathname);
                var CurrentPath = CurrentPathName.substring(0, CurrentPathName.lastIndexOf("/") + 1);
                var strActionPage = CurrentPath + "SaveToFile.aspx";
                DWObject.IfSSL = false; // Set whether SSL is used
                DWObject.HTTPPort = location.port == "" ? 80 : location.port;

                var Digital = new Date();
                var uploadfilename = Digital.getMilliseconds(); // Uses milliseconds according to local time as the file name

                // Upload the image(s) to the server asynchronously
                DWObject.HTTPUploadAllThroughPostAsPDF(strHTTPServer, strActionPage, uploadfilename + ".pdf");

                DWObject.RemoveAllImages();  // remove all the scanned images from buffer after uploading them to the server


        function DWObject_OnPostTransfer(){ // OnPostTransfer event will be triggered automatically after each paper scan
            DWObject.IfShowProgressBar = false;


Server Side – SaveToFile.aspx:

<%@ Page Language="c#" AutoEventWireup="false" Debug="True"%>

    HttpFileCollection files = HttpContext.Current.Request.Files;
    HttpPostedFile uploadfile = files["RemoteFile"];
    uploadfile.SaveAs(System.Web.HttpContext.Current.Request.MapPath(".") + "/" + uploadfile.FileName);

Get Samples You can get the complete sample code here.

30-day free trial of Dynamic Web TWAIN is available here.

If you have any questions, you can contact our support team at

Search Blog Posts