TWAIN scanning and document capture is an essential aspect and starting point of most document imaging applications.  For web developers, this is a problematic requirement due to the localized, hardware-dependent nature of TWAIN scanners and image capture devices.  Many roadblocks await the developer and most often the client is left with tedious and time-wasting inconveniences that make the application difficult to use.  For example, scanning in a separate application creates a laborious workflow for the client.  Browser plug-ins limit the flexibility of your application by locking it into specific browsers.  Last but not least, updating and maintaining multiple code-bases can turn your web-based scanning application into a nightmare. 


LEADTOOLS has developed a Web Scanning SDK that solves many of these obstacles and offers a programmer-friendly and customizable framework for integrating TWAIN scanning into any web-based document imaging solution.  In this white paper, we will explore the inner-workings of this innovative framework and highlight how developers can write just a few lines of code to extend and customize it for their application.


LEADTOOLS Web Scanning Components and Architecture

LEADTOOLS Web Scanning consists of three major components: a Self-hosted Web Service, a cross-browser web interface built with HTML5 and JavaScript, and a Server-side Upload Web Service.  Each of these components is designed with maximum extensibility in mind and makes it possible to create a robust web application with simple update procedures and separation of concerns for multi-developer teams.


web scanning diagram


The flexibility of this architecture allows developers to utilize one or more components for new projects, or for adding web scanning functionality to their existing web enterprise solution.


Self-hosted Web Service

At the heart of the LEADTOOLS Web Scanning application is the ScanningService, a Self-hosted Web Service (SHWS).  This is a necessary component, since the TWAIN device's drivers can only be installed on the client machine.  The SHWS receives REST commands via JavaScript that allow the browser client to select the TWAIN source, negotiate TWAIN capabilities, get the status, and acquire images to a local cache which the web application can load via URI.


_scanningService.acquire(true, function (status) {

   for (; _totalScannedPages < status.scandPagesNumber; _ui.lastPageNumber++) {

      _thumbnail.addThumbnail(_ui.lastPageNumber + 1, false);




The SHWS is capable of implementing any of LEADTOOLS' 200+ image processing functions through a customizable AddIn interface.  The ApplyImageProcessingCommand web service function will call the class implementing IImageProcessingAddIn and apply the image processing function and parameters to the image and return the image through a client-accessible URI. 

All the AddIn needs is a function named GetIPCommand that returns a CommandCallBack object.

public CommandCallBack GetIPCommand(string name)


   switch (name)


      case "Flip":

         return FlipImage;


      case "Rotate":

         return RotateImage;


      case "Deskew":

         return DeskewImage;


      case "HolePunchRemove":

         return RemoveImageHolePunch;


      case "BorderRemove":

         return RemoveImageBorder;



         return null;




private void DeskewImage(RasterImage image, string commandParam)


   int angleRange = ScanningHelper.JsonStringToInteger(commandParam, "angleRange");

   int angleResolution = ScanningHelper.JsonStringToInteger(commandParam, "angleResolution");

   RasterColor fillColor = ScanningHelper.JsonStringToRasterColor(commandParam, "fillColor");

   int flags = ScanningHelper.JsonStringToInteger(commandParam, "flags");


   DeskewCommand cmd = new DeskewCommand(fillColor, (DeskewCommandFlags)flags);

   cmd.AngleRange = angleRange;

   cmd.AngleResolution = angleResolution;




Then from the client-side JavaScript, calling the SHWS takes just a few lines of code:

var commandParam: any = new Object();

commandParam.fillColor = JSON.stringify(fillColor);

commandParam.flags = flags;

commandParam.angleRange = 0;

commandParam.angleResolution = 0;

_scanningService.applyImageProcessingCommand("Deskew", _currentPageNumber, JSON.stringify(commandParam), onSuccess, onFailed);

HTML5 / JavaScript Web Application

The client drives the application with a robust web interface that uses LEADTOOLS HTML5 Image Viewing controls and communicates with the SHWS through RESTful JavaScript commands.  The demo that ships with LEADTOOLS includes the thumbnail browser, image viewer, and several client-side tools including pan, zoom, fit, stretch and magnifying glass.  Additional features can easily be added including annotations and markup, drag and drop, and more.  Best of all, since this application is designed using HTML5 and JavaScript, it can run without any browser plugins on any supported browser on a Windows machine running the SHWS.


Server-side Upload Web Service

After the documents have been scanned and processed on the client side using the HTML5 interface and SHWS, the newly created images can be uploaded to the server for additional processing.  In the shipping example application, the UploadService can convert the file to any of LEADTOOLS 150+ supported file formats and then return the URI to the client for downloading.  Adding support for new file formats only requires adding a few lines of code to a switch statement within the EndDocument function inside the upload service.

RasterImageFormat saveFormat;

switch (mimeType.ToLower())


   case "application/pdf":

      documentFullName = Path.Combine(storeFolderPath, name + ".pdf");

      saveFormat = RasterImageFormat.RasPdfJpeg411;


   case "image/tiff":

      documentFullName = Path.Combine(storeFolderPath, name + ".tif");

      saveFormat = RasterImageFormat.TifJpeg411;



      throw new ArgumentException(string.Format("'{0}' not Supported Format", mimeType));


The source code for the upload service is provided and can be fully customized if more advanced processing is required.  The IUploadService interface lays the groundwork for sending customized user data, and implementing any functionality within LEADTOOLS including OCR, Barcode, Forms Recognition, saving to SharePoint and much more.



Scanning documents into digital image formats within a cross-browser HTML5 solution is just one of many real-world solutions you can tackle with LEADTOOLS.  Its state-of-the-art Web Scanning SDK makes it possible to create innovative new web applications for capturing documents, and offers a programmer-friendly and modular architecture for adding web scanning to any existing web application or workflow.  It also opens the door for extending your web-based document imaging solution with any of the many additional technologies in LEADTOOLS Imaging SDKs.  LEADTOOLS offers an incredible value with its comprehensive family of toolkits for raster, document, medical and multimedia imaging.  For more information on how LEAD Technologies can image-enable your application and boost your ROI, visit to download a free evaluation, or give us a call at +1-704-332-5532.