Twain.Wia.Sane.Scanner 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Twain.Wia.Sane.Scanner --version 1.0.0                
NuGet\Install-Package Twain.Wia.Sane.Scanner -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Twain.Wia.Sane.Scanner" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Twain.Wia.Sane.Scanner --version 1.0.0                
#r "nuget: Twain.Wia.Sane.Scanner, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Twain.Wia.Sane.Scanner as a Cake Addin
#addin nuget:?package=Twain.Wia.Sane.Scanner&version=1.0.0

// Install Twain.Wia.Sane.Scanner as a Cake Tool
#tool nuget:?package=Twain.Wia.Sane.Scanner&version=1.0.0                

.NET Document Scanner for TWAIN, WIA, SANE, ICA, and eSCL

The package provides methods for calling Dynamsoft Service REST APIs. This allows developers to build .NET applications for digitizing documents from TWAIN (32-bit/64-bit), WIA, SANE, ICA and eSCL scanners.

Prerequisites

  1. Install Dynamsoft Service.

  2. Request a free trial license.

Dynamsoft Service REST API

By default, the REST API's host address is set to http://127.0.0.1:18622.

Method Endpoint Description Parameters Response
GET /DWTAPI/Scanners Get a list of scanners None 200 OK with scanner list
POST /DWTAPI/ScanJobs Creates a scan job license, device, config 201 Created with job ID
GET /DWTAPI/ScanJobs/:id/NextDocument Retrieves a document image id: Job ID 200 OK with image stream
DELETE /DWTAPI/ScanJobs/:id Deletes a scan job id: Job ID 200 OK

You can navigate to http://127.0.0.1:18625/ to access the service. To make it accessible from desktop, mobile, and web applications on the same network, you can change the host address to a LAN IP address. For example, you might use http://192.168.8.72.

dynamsoft-service-config

The scanner parameter configuration is based on Dynamsoft Web TWAIN documentation.

Quick Start

Replace the license key in the code below with a valid one and run the code.

using System;
using System.Collections.Generic;
using Twain.Wia.Sane.Scanner;

public class Program
{
    private static string licenseKey = "LICENSE-KEY";
    private static ScannerController scannerController = new ScannerController();
    private static List<Dictionary<string, object>> devices = new List<Dictionary<string, object>>();
    private static string host = "http://127.0.0.1:18622";
    private static string questions = @"
Please select an operation:
1. Get scanners
2. Acquire documents by scanner index
3. Quit
";

    public static async Task Main()
    {
        await AskQuestion();
    }

    private static async Task<int> AskQuestion()
    {
        while (true)
        {
            Console.WriteLine(".............................................");
            Console.WriteLine(questions);
            string? answer = Console.ReadLine();

            if (string.IsNullOrEmpty(answer))
            {
                continue;
            }

            if (answer == "3")
            {
                break;
            }
            else if (answer == "1")
            {
                var scanners = await scannerController.GetDevices(host, ScannerType.TWAINSCANNER | ScannerType.TWAINX64SCANNER);
                devices.Clear();
                for (int i = 0; i < scanners.Count; i++)
                {
                    var scanner = scanners[i];
                    devices.Add(scanner);
                    Console.WriteLine($"\nIndex: {i}, Name: {scanner["name"]}");
                }
            }
            else if (answer == "2")
            {
                if (devices.Count == 0)
                {
                    Console.WriteLine("Please get scanners first!\n");
                    continue;
                }

                Console.Write($"\nSelect an index (<= {devices.Count - 1}): ");
                int index;
                if (!int.TryParse(Console.ReadLine(), out index))
                {
                    Console.WriteLine("Invalid input. Please enter a number.");
                    continue;
                }

                if (index < 0 || index >= devices.Count)
                {
                    Console.WriteLine("It is out of range.");
                    continue;
                }

                var parameters = new Dictionary<string, object>
                {
                    {"license", licenseKey},
                    {"device", devices[index]["device"]}
                };

                parameters["config"] = new Dictionary<string, object>
                {
                    {"IfShowUI", false},
                    {"PixelType", 2},
                    {"Resolution", 200},
                    {"IfFeederEnabled", false},
                    {"IfDuplexEnabled", false}
                };

                string jobId = await scannerController.ScanDocument(host, parameters);

                if (!string.IsNullOrEmpty(jobId))
                {
                    var images = await scannerController.GetImageFiles(host, jobId, "./");
                    for (int i = 0; i < images.Count; i++)
                    {
                        Console.WriteLine($"Image {i}: {images[i]}");
                    }

                    scannerController.DeleteJob(host, jobId);
                }
            }
            else
            {
                continue;
            }
        }
        return 0;
    }
}

Example

API

  • public async Task<List<Dictionary<string, object>>> GetDevices(string host, int? scannerType = null): Get a list of available devices.
  • public async Task<string> ScanDocument(string host, Dictionary<string, object> parameters): Scan a document.
  • public async void DeleteJob(string host, string jobId): Delete a job.
  • public async Task<string> GetImageFile(string host, string jobId, string directory): Get an image file.
  • public async Task<List<string>> GetImageFiles(string host, string jobId, string directory): Get a list of image files.
  • public List<byte[]> GetImageStreams(string host, string jobId): Get a list of image streams.
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net7.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.0 256 8/15/2024
1.1.0 586 10/25/2023
1.0.1 191 10/10/2023
1.0.0 172 10/10/2023

- Support TWAIN, SANE, WIA, ICA and eSCL compatible scanners on Windows, Linux and macOS.