Document Scanning from ASP.net Web Application

15.4k views Asked by At

I have a ASP.Net C# 4.0 Web Application

I need to Add a scanning feature for my users. This is what I want to achieve On my web application

  1. user clicks on a button
  2. opens a window with preview of document in Scanning device attached to the client system
  3. User confirms the Scan
  4. this will save the Scanned document in jpg/pdf format on the server
  5. then do the OCR on document

Can any one suggest a way to achieve this.

I read about this https://www.leadtools.com/sdk/engine/imaging not sure how much this can work. Can any one suggest a best way to get this done.

Thanks

update

tried leadtools from https://www.leadtools.com/support/forum/posts/m28036-Re--Scan-and-Upload-v16--NET-with-Caspol-exe-deployment as LEAD Support suggested but it is missing references not sure where and how to get those references enter image description here

3

There are 3 answers

3
LEADTOOLS Support On BEST ANSWER

HaBo, This is LEAD support. Since you mentioned our LEADTOOLS toolkit, the answer to your question is yes. Our toolkit can be used to implement either of the 2 approaches mentioned by tgolisch.

For the click-once approach, you simply use our Windows Forms controls that contain Twain support and package your application for ClickOnce deployment. This is done, for example, in this demo project: LEADTOOLS ClickOnce Demos

For the custom control approach, see the example code projects on our forums that perform Scan and Upload

0
tgolisch On

Web browsers don't have permissions to use system devices like this(major security issue). There are 2 common ways of getting around this:

  1. Make a custom control to run in your browser (flash, silverlight, java applet).
  2. Make a "click-once deployment app" that a user launches from your page.

Both approaches would send the data back to your server via web services or WCF, etc.

0
Aziz Nortozhiev On

Solution is here:

  1. In ASP.Net/Core Project you send message to call winform project:

            var start = function () {
            var i = 0;
            var wsImpl = window.WebSocket || window.MozWebSocket;
            window.ws = new wsImpl('ws://localhost:8181/');
            ws.onmessage = function (e) {
                $('#submit').hide();
                $('#scanBtn').hide();
                $('.loader').show();
                if (typeof e.data === "string") {
                    //IF Received Data is String
                }
                else if (e.data instanceof ArrayBuffer) {
                    //IF Received Data is ArrayBuffer
                }
                else if (e.data instanceof Blob) {
                    i++;
                    var f = e.data;
                    f.name = "File" + i;
                    storedFiles.push(f);
                    formdata.append(f.name, f);
                    var reader = new FileReader();
                    reader.onload = function (e) {
                        var html = "<div class=\"col-sm-2 text-center\" 
                    style=\"border: 1px solid black; margin-left: 2px;\"><img 
                    height=\"200px\" width=\"200px\" src=\"" + e.target.result + "\" 
                    data-file='" + f.name + "' class='selFile' title='Click to 
                    remove'><br/>" + i + "</div>";
                        selDiv.append(html);
                        $('#submit').show();
                        $('#scanBtn').show();
                        $('.loader').hide();
                    }
                    reader.readAsDataURL(f);
                }
            };
            ws.onopen = function () {
                //Do whatever u want when connected succesfully
            };
            ws.onclose = function () {
                $('.dalert').modal('show');
            };
        }
        window.onload = start;
        function scanImage() {
            ws.send("1100");
        };
    

https://javascript.info/websocket

  1. In Winforms Project you scan document and send graphic data back to Asp.Net/Core project:

    public partial class Form1 : Form { ImageCodecInfo _tiffCodecInfo; TwainSession _twain; bool _stopScan; bool _loadingCaps; List allSockets; WebSocketServer server; public Form1() { InitializeComponent();

     if (NTwain.PlatformInfo.Current.IsApp64Bit)
    {
        Text = Text + " (64bit)";
    }
    else
    {
        Text = Text + " (32bit)";
    }
    foreach (var enc in ImageCodecInfo.GetImageEncoders())
    {
        if (enc.MimeType == "image/tiff") { _tiffCodecInfo = enc; break; }
    }
    
    this.WindowState = FormWindowState.Minimized;
    this.ShowInTaskbar = false;
    
    allSockets = new List<IWebSocketConnection>();
    server = new WebSocketServer("ws://0.0.0.0:8181");
    server.Start(socket =>
    {
        socket.OnOpen = () =>
        {
            Console.WriteLine("Open!");
            allSockets.Add(socket);
        };
        socket.OnClose = () =>
        {
            Console.WriteLine("Close!");
            allSockets.Remove(socket);
        };
        socket.OnMessage = message =>
        {
            if (message == "1100")
            {
                this.Invoke(new Action(()=> {
                    this.WindowState = FormWindowState.Normal;
                }));
            }
        };
    });
    

    }

Link to project.

https://github.com/mgriit/ScanAppForWeb

You can remake this project, as you want.