Features

Supports Almost All Scanners: Acer, AGFA, Brother, Canon, Dell, Epson, Fujitsu, HP, IBM, Kodak, Konica Minolta, Lexmark, NEC, Nikon, Olympus, Panasonic, Ricoh, Samsung, Xerox and many more TWAIN WIA scanners and cameras;

Supports Both 64bit & 32bit Apps: probably the only scanning library that works for both 64bit and 32bit applications thanks to our innovative patent pending technology and quality implementation

JPG, PDF, PDF/A, TIFF, CCITT G4: Regardless the scanner's native output formats, Asprise Scan supports a wide range of output formats such as BMP, PNG, JPEG and multi-page PDF, PDF/A (to meet compliance requirements), TIFF with CCITT G4 compression.

HIPPA, HITECH Privacy Compliant: empowers you to scan entirely in memory, with zero temporary file. Many government agencies also rely on Asprise to simplify the complexity of HIPPA and HITECH's technical requirements

Fast Flatbed And ADF Scanning: high speed scanning from flatbed devices and automatic document feeder (ADF) scanners to increase the user's productivity effortless. Advanced features of scanners are supported: imprinter, endorser, barcode and patchcode;

Generates Thumbnails & Upload To Web Servers Directly: generate thumbnails when scanning. Additionally, regardless of your server side technology (C# ASP.NET, Java JSP, PHP, Python, Ruby on Rails), Asprise Scanning SDK allows you to upload scanned images to web servers;

Barcode Reading & Blank Page Detection: Reads barcode (CODE 128, EAN 8/13, UPC, Code 3 of 9, QR, etc.) from scanned documents - even if the scanner doesn't support it. Configurable blank page detection is available for you to discard blank pages.

Introduction

This code sample demostrates how to scan documents from TWAIN WIA scanners in JPEG or PDF formats for Windows Forms and WPF applications.

Building the Sample

Download and unzip the sample project. Open it with Visual Studio 2013 or higher. Press F5 to run it.

Description

Suppose that we need to scan color US letter documents and save the result in JPEG files. The following code demonstrates how to use Asprise .NET Scanning API to achieve that:

using asprise_imaging_api;

Result result = new AspriseImaging().Scan(new Request()
    .SetTwainCap(TwainConstants.ICAP_PIXELTYPE, TwainConstants.TWPT_RGB)
    .SetTwainCap(TwainConstants.ICAP_SUPPORTEDSIZES, TwainConstants.TWSS_USLETTER)
    .SetPromptScanMore(true) // prompt to scan more pages
    .AddOutputItem(new RequestOutputItem(AspriseImaging.OUTPUT_SAVE, AspriseImaging.FORMAT_JPG)
      .SetSavePath(".\\${TMS}${EXT}")), // Environment variables in path will be expanded
  "select", true, true); // "select" prompts device selection dialog.

List<string> files = result == null ? null : result.GetImageFiles();
Console.WriteLine("Scanned: " + string.Join(", ", files == null ? new string[0] : files.ToArray()));
Imports asprise_imaging_api

Dim result As Result = New AspriseImaging().Scan(New Request()
   .SetTwainCap(TwainConstants.ICAP_PIXELTYPE, TwainConstants.TWPT_RGB)
   .SetTwainCap(TwainConstants.ICAP_SUPPORTEDSIZES, TwainConstants.TWSS_USLETTER)
   .SetPromptScanMore(True) ' prompt to scan more pages
   .AddOutputItem(New RequestOutputItem(AspriseImaging.OUTPUT_SAVE, AspriseImaging.FORMAT_JPG)
      .SetSavePath(".\${TMS}${EXT}")), ' Environment variables in path will be expanded
  "select", True, True) ' "select" prompts device selection dialog.

Dim files As List(Of String) = If(result Is Nothing, Nothing, result.GetImageFiles())
Console.WriteLine("Scanned: " & String.Join(", ", If(files Is Nothing, New String(-1) {}, files.ToArray())))

Alternatively, Asprise C# VB.NET Scanning SDK also allows you to specify scan requests using JSON based scan DSL (please refer to Asprise Scanning Request DSL for details). The code below is equivalent to the OO based code:

Result result = new AspriseImaging().Scan("{" +
    "  \"twain_cap_setting\" : {" +
    "    \"ICAP_PIXEXELTYPE\" : \"TWPT_RGB\"," +
    "    \"ICAP_SUPPORPORTEDSIZES\" : \"TWSS_USLESLETTER\"" +
    "  }," +
    "  \"prompt_scan_more\" : true," +
    "  \"output_settings\" : [ {" +
    "    \"type\" : \"save\"," +
    "    \"format\" : \"jpg\"," +
    "    \"save_path\" : \".\\\\${TMS}${EXT}\"" +
    "  } ]" +
    "}", "select", true, true);

List<string> files = result == null ? null : result.GetImageFiles();
Console.WriteLine("Scanned: " + string.Join(", ", files == null ? new string[0] : files.ToArray()));

More Scanning Scenarios

Scan And Upload To Server

It’s easy to allow the user to scan from TWAIN WIA scanners in JPG or PDF and upload to the server. The server side script to handle the upload can be written in any programming language, ASP.NET, Java, PHP, Python, Ruby, etc. You handle the upload from Asprise Scanning SDK in the same way as you handle a simple HTML form upload.

Result result = new AspriseImaging().Scan(new Request().AddOutputItem(
  new RequestOutputItem(AspriseImaging.OUTPUT_UPLOAD, AspriseImaging.FORMAT_JPG).SetUploadSetting( // Upload
    new UploadSetting("http://asprise.com/scan/applet/upload.php?action=dump")
      .AddPostField("title", "Test scan"))) // Additional data to be passed to server: post fields, headers, etc.
 "select", true, true);

String response = result == null ? null : result.GetUploadResponse();
Console.WriteLine("From server: \n" + response);

// Alternatively, request can be specified using JSON
Result result = new AspriseImaging().Scan("{" +
  "  \"output_settings\" : [ {" +
  "    \"type\" : \"upload\"," +
  "    \"format\" : \"jpg\"," +
  "    \"upload_target\" : {" +
  "      \"url\" : \"http://asprise.com/scan/applet/upload.php?action=dump\"," +
  "      \"post_fields\" : {" +
  "        \"title\" : \"Test scan\"" +
  "      }" +
  "    }" +
  "  } ]" +
 "}", "select", true, true);

Scan Multiple Pages As PDF

Scanning multiple pages as a single PDF file simplifies organization. To do so, you need to set the format type to AspriseImaging.FORMAT_PDF. Additionally, you may add a text line to the bottom of the first page and set EXIF tags.

Result result = new AspriseImaging().Scan(new Request().AddOutputItem(
  new RequestOutputItem(AspriseImaging.OUTPUT_SAVE, AspriseImaging.FORMAT_PDF)
    .SetPdfTextLine("Scanned on ${DATETIME} by user X") // Optional text line at the bottom of the 1st page
    .AddExifTag("DocumentName", "Scan to PDF by Asprise") // Optional PDF doc properties (metadata)
    .SetSavePath(".\\${TMS}${EXT}")
  ).SetPromptScanMore(true) // whether to prompt user to scan more pages
 , "select", true, true);

string pdfFile = result == null ? null : result.GetPdfFile();
Console.WriteLine("Documents scanned as PDF: " + pdfFile);

// Alternatively, request can be specified using the following JSON:
{
  "output_settings" : [ {
    "type" : "save",
    "format" : "pdf",
    "pdf_text_line" : "Scanned on ${DATETIME} by user X",
    "pdf_owner_password" : "",
    "pdf_user_password" : "",
    "exif" : {
      "DocumentName" : "Scan to PDF by Asprise"    },
    "save_path" : ".\\${TMS}${EXT}"  } ],
  "prompt_scan_more" : true
}

ADF With Optional Blank Page Detection

Automatic Document Feeder (ADF) allows bulk scanning of multiple pages in a single session. Optionally, you may choose to automatically discard blank page.

Result result = new AspriseImaging().Scan(new Request()
  .SetTwainCap(TwainConstants.CAP_FEEDERENABLED, true) // select feeder instead of flatbed
  .SetTwainCap(TwainConstants.CAP_AUTOFEED, true)
  .SetTwainCap(TwainConstants.CAP_DUPLEXENABLED, true)
  .SetDiscardBlankPages(true)
  .SetBlankPageThreshold(0.02m) // Discard pages with ink coverage < 2%
  .AddOutputItem(new RequestOutputItem(AspriseImaging.OUTPUT_SAVE, AspriseImaging.FORMAT_PDF).SetSavePath(".\\${TMS}${EXT}")),
 "select", true, true);

string pdfFile = result == null ? null : result.GetPdfFile();
Console.WriteLine("Documents scanned as PDF: " + pdfFile);

// Alternatively, request can be specified using the following JSON:
{
    "twain_cap_setting" : {
      "CAP_FEEDERENABLED" : true,
      "CAP_AUTOFEED" : true,
      "CAP_DUPLEXENABLED" : true
    },
    "discard_blank_pages" : true,
     // pages with ink coverage below the threshold will be discarded
    "blank_page_threshold" : "0.02", // default value is 0.02
    "output_settings" : [ {
      "type" : "save",
      "format" : "pdf",
      "save_path" : ".\\${TMS}${EXT}"    } ]
 }
 

More Information

Learn more about Asprise Scan C# VB.NET SDK for TWAIN WIA Scanners

Access to Asprise Scan C# VB.NET Developer's Guide

Browse API (MSDN style) online

Last edited Aug 19, 2016 at 7:28 AM by asprise, version 4