How can I trigger a scanner from a browser?
Asked Answered
C

6

18

I have Fujitsu fi-6130 TWAIN / ISIS scanners that I'd like to trigger from a button in a jQuery Rails web page. Not only would I like to have the page tell the scanner to "go", I'd also like to upload the resulting file via Paperclip once the (single) page is scanned - ideally without requiring the user to navigate a file explorer widget to find the file manually.

Each scanner is USB attached to a Windows XP desktop, though we may replace these call center desktops with Google Chrome OS.

This question was asked almost a year ago, but mainly received suggestions requiring the use of commercial IE .NET products that cost several hundred dollars - Interfacing with the end-user's scanner from a webapp (web/scanner integration)

Callipygian answered 17/8, 2010 at 15:39 Comment(3)
Its not really possible to interface a browser with a scanner(darn). Have the user scan the image themselves and upload it.Limen
One way to talk with a scanner in a browser is through ActiveX control (IE) or browser plugin (Firefox, Chrome). as far as i know, there is no such open source SDK out there. better to spend several hundred dollars than start from scratch. twain is the most popular protocol for scanner drivers, and it's hard to crackPromoter
scanner.js allows you to invoke scanners from browsers on Windows or Mac OS. It's a commercial package too.Unthoughtof
M
18

This isn't possible from directly within a standard HTML/js page - js has no permissions to access peripherals like scanners.

It may well be possible using either flash or silverlight but suspect you'd hit permissions issues. There's articles here and here but it may be a) too involved and b) not quite what you're after.

If you control the machines the web app will be running on, I'd recommend using a simple desktop client to perform the scan and allowing connections to it from within the webpage by opening up a local port

so js does an AJAX call to (say) http://localhost:1234/Services/Scan which returns an image

Edit: With regards to writing the desktop client, you've got a number of options. I'd personally recommend you not try to do this in PERL/PHP as they don't seem to be the right tool for the job and I suspect you'll end up loading COM objects to try and access TWAIN devices (and we all know how much fun that is...)

In the comments, you've indicated you don't like Visual Studio - So if you're familiar with Java, I'd suggest you have a look at JTwain (commercial but seems to be good quality) or start reading here. NB: I'm not a frequent java developer so can't guarantee either of the above is exactly what you need.

Beyond that, I'd suggest C++ using a different IDE (although this wouldn't be OS-agnostic)

Milliemillieme answered 17/8, 2010 at 15:50 Comment(13)
The program that gets configured to proxy a subset of the scanner's api as a web service has probably been written more than a few times... In fact, I'm surprised the scanner vendors don't supply one for the popular desktops. I'll bet a significant fraction of the customers for high-end scanners want it. Does anyone know of one off-the-shelf?Callipygian
I don't but now I'm tempted to write one :)Milliemillieme
I contacted Fujitsu via email, chat, and phone. They have no such utility for any desktop os, though I made sure they noted my request, and suggested that they reply directly to this Stackoverflow question. I'd prefer to write a scanner-to-listening-socket relay in a language familiar to me, but Ruby and Python have to be installed separately on Windows. C++ programs have to be produced in that damn Visual Studio. A native windows scripting language would be better from a call center support perspective, but I don't know any. And then the proxy would work only as long as we use Windows.Callipygian
We've built a local "client desktop service" (as we call it) for one of the webapps we've built, although it doesn't have any feature to acquire from a scanner, though that shouldn't be too difficult to build. The biggest problem we ran into is that the local web server needs to have SSL since the webapp also uses SSL and today browsers don't let you call insecure Services/API's. Among others, this is one big reason why vendors might not supply such a software.Perfectionism
@Perfectionism FWIW, if you need to, you can create your own certificate authority, install its certificate into the local trusted store and then use it to generate self-signed certificates that the local machine will accept as valid. Only possible if you have admin permissions during install, but not insurmountable. In any case, Glad you've got a hack that will get you where you need to beMilliemillieme
@Milliemillieme Have you managed to handle errors like scanner is turned off? I tried your above solution using an ajax call but I don`t get an error message from the scan app when the scanner is turned off (the error message appears as a popup message box) or when there is no paper in the feeder.Chaiken
@shahareldad I never implemented this myself, merely provided suggestions. That said... If you're writing the desktop app that exposes the scanner functionality, presumably you can modify it so that instead of showing a message box on errors, it returns an error code / status message to the AJAX request?Milliemillieme
@Milliemillieme I tried that and its not that easy after the part where you start using the form handle the TWAIN API requires. I am now thinking of generating a UI for the form (even though I wish there wasn`t) just to be able to display error messages.Chaiken
You can see code sample for impl. a local windows service and sending it http requests @ my github. Check the ServerSide "WindowsService for running http calls" folder for the windows service and the indexWebApiServices.html file for the browser code.Chaiken
@Milliemillieme Forgive my ignorance, I am going to create a c# exe to scan a document. But I don't understand how can I call it from an AJAX function, nor how can I retrieve the scanned image from it. You mentioned it as if it was too obvious, but it's not quite obvious to me.Jeaz
Hi @Lamar, not a problem. There are numerous options. At the most fundamental level, you need to open a network port and start listening for traffic. That could be opening a socket and listening for network traffic, or finding a ready-made server. Windows Communication Foundation (WCF) is part of the framework and really powerful but quite complex to configure. For something this simple (one or two methods, to get scans/config) and not much need for flexibility, you could start from something like this: codeproject.com/Articles/137979/Simple-HTTP-Server-in-C [link updated]Milliemillieme
@Jeaz [Or I may have misunderstood your wuestion - alternate answer]: An AJAZ request is just a connection over which you request a page. "Localhost" is the local machine so http://localhost:10000 means "Send an HTTP request to port 10,000 on the local computer". So your job is to write a program that listens for connections on port 10000, then reads the request sent by your javascript (the AJAX request) and then provide an appropriate response.Milliemillieme
@Milliemillieme Thanks a lot! now it makes sense to me!Jeaz
D
13

There is a solution called Dynamic Web TWAIN from Dynamsoft which provides a Browser-based TWAIN SDK for acquiring images from TWAIN devices, and editing and saving them to remote databases.

Doykos answered 24/1, 2013 at 20:58 Comment(2)
Too expensive, I mean I have an application that I need to install on multiple servers. If I'd go with Dynamic's solution, I'd end up spending on the scanning part more than the whole application itself.Jeaz
Plz mention somewhere that you are selling your commercial solution in the answer.Behindhand
P
4

Here is a free open source option I found:

https://github.com/mgriit/ScanAppForWeb

If someone was to take this concept and combine it with NAPS2 ( https://www.naps2.com/ )

it would make a really great solution...

Percolate answered 8/6, 2022 at 14:52 Comment(1)
did you have success using this free project?Bingo
U
2

As @Basic mentioned, JTwain can be used to create such a solution. In fact, the developer of JTwain has created ScannerJS that allows one to scan directly from browsers like IE, Chrome and Firefox using JavaScript. In order to use it in your web pages, you need:

Include scanner.js:

<html lang="en"><head>
<script src="//asprise.azureedge.net/scannerjs/scanner.js" type="text/javascript"></script>

and call scanner.scan:

function scanToWebPageAndUploadToWebServer() {
   scanner.scan(displayImagesOnPage,
{
"twain_cap_setting": {
    "ICAP_PIXELTYPE": "TWPT_GRAY",
    "ICAP_XRESOLUTION": "200",
    "ICAP_YRESOLUTION": "200"
},
"prompt_scan_more": true,
"discard_blank_pages": "false",
"blank_page_threshold": "0.02",
"output_settings": [
    {
        "type": "return-base64-thumbnail",
        "format": "jpg",
        "thumbnail_height": 200
    },
    {
        "type": "upload",
        "format": "pdf",
        "pdf_force_black_white": "false",
        "pdfa_compliant": "false",
        "pdf_text_line": "By ${USERNAME} on ${DATETIME}",
        "exif": {
            "DocumentName": "Doc Scan Powered by Asprise.com",
            "UserComment": "Scanned using Asprise software"
        },
        "upload_target": {
            "url": "https://asprise.com/scan/applet/upload.php?action=dump",
            "max_retries": 2,
            "post_fields": {
                "provider": "Asprise"
            },
            "cookies": "name=Asprise; domain=asprise.com",
            "auth": "user:pass",
            "headers": [
                "Referer: http://asprise.com"
            ],
            "log_file": "null",
            "max_operation_time": 600
        }
    }
]
}

    );
    }
Unthoughtof answered 17/6, 2016 at 6:14 Comment(4)
is scanner.js and the software is free for very low-level basic uses.Pernell
"In fact, the developer of JTwain has created..." Any reason you're talking about yourself in the 3rd person?Milliemillieme
I can't see the free version in their website: asprise.com/document-scan-upload-image-browser/… How can we try it?Jeaz
Plz mention somewhere that you are selling your commercial solution in the answer. This thread isn't about scanner.js.Behindhand
M
1

You can use a signed applet, using a library like MMS computing's. You can see it in use in an applet in the codebase of OpenKM.

Mealy answered 18/5, 2012 at 19:55 Comment(0)
B
1

It seems there's a Web API toolkit available for Fujitsu fi series scanners. Its basically an app you install on client machine where the scanner is that accepts calls via JSON or Silverlight and sends them to the scanner drivers.

http://uk.emc.com/enterprise-content-management/captiva/cloud-toolkit.htm

I've just downloaded it and am reading trough the docs, so can't vouch it works.

Bricole answered 19/7, 2013 at 9:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.