4

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

BonzoFestoon
  • 181
  • 1
  • 2
  • 12
HaBo
  • 13,999
  • 36
  • 114
  • 206

3 Answers3

2

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

BonzoFestoon
  • 181
  • 1
  • 2
  • 12
LEADTOOLS Support
  • 2,755
  • 1
  • 12
  • 12
  • Thank you for the links, will try the custom control and post here how it went for me. Can I use this control on .Net Framework 4.0? – HaBo Aug 26 '12 at 20:51
  • 1
    Yes, you can. Most of our .Net controls support .Net framework 4.0, we also have editions for the other versions of the .Net framework. Also, they support both 32-bit and 64-bit applications. About the missing references question, to get the DLLs, you should download our toolkit on your PC and add them as references to the application. You can download the free evaluation edition of LEADTOOLS v17.5 using this page: http://www.leadtools.com/downloads/evaluationform.htm If you have further questions, please contact our support team at support@leadtools.com and we would be happy to assist you. – LEADTOOLS Support Aug 28 '12 at 14:21
  • 1
    This is borderline advertisement. – Austin Henley Sep 24 '12 at 21:52
2

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.

Aziz Nortozhiev
  • 365
  • 5
  • 8
0

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.

tgolisch
  • 6,549
  • 3
  • 24
  • 42