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)

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Randy J Parker
  • 461
  • 1
  • 4
  • 8
  • 2
    Its not really possible to interface a browser with a scanner(darn). Have the user scan the image themselves and upload it. – tcooc Aug 17 '10 at 15:42
  • 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 crack – flysakura Sep 12 '12 at 09:44
  • 1
    [scanner.js](http://asprise.com/document-scan-upload-image-browser/direct-to-server-php-asp.net-overview.html) allows you to invoke scanners from browsers on Windows or Mac OS. It's a commercial package too. – Scanner.js Receipt Invoice OCR Feb 25 '15 at 06:36

6 Answers6

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)

Basic
  • 26,321
  • 24
  • 115
  • 201
  • 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? – Randy J Parker Aug 17 '10 at 18:30
  • I don't but now I'm tempted to write one :) – Basic Aug 17 '10 at 20:58
  • 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. – Randy J Parker Aug 18 '10 at 17:43
  • 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. – HK1 Apr 06 '17 at 15:46
  • @HK1 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 be – Basic Apr 06 '17 at 18:57
  • @Basic 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. – shahar eldad Jan 11 '18 at 13:00
  • @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? – Basic Jan 11 '18 at 13:30
  • @Basic 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. – shahar eldad Jan 14 '18 at 07:54
  • You can see code sample for impl. a local windows service and sending it http requests @ my [github](https://github.com/shahareldad/HtmlFun). Check the ServerSide "WindowsService for running http calls" folder for the windows service and the indexWebApiServices.html file for the browser code. – shahar eldad Jul 10 '18 at 13:13
  • @Basic 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. – Lamar Jun 10 '19 at 07:51
  • 1
    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: https://www.codeproject.com/Articles/137979/Simple-HTTP-Server-in-C [link updated] – Basic Jun 11 '19 at 15:13
  • 1
    @Lamar [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. – Basic Jun 11 '19 at 18:34
  • @Basic Thanks a lot! now it makes sense to me! – Lamar Jun 13 '19 at 06:38
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.

  • 1
    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. – Lamar Aug 18 '19 at 08:30
  • 1
    Plz mention somewhere that you are selling your commercial solution in the answer. – Salik Apr 30 '20 at 08:06
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...

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
        }
    }
]
}

    );
    }
  • is scanner.js and the software is free for very low-level basic uses. – nilesh Sep 12 '17 at 19:03
  • 13
    "In fact, the developer of JTwain has created..." Any reason you're talking about yourself in the 3rd person? – Basic Feb 13 '18 at 16:48
  • I can't see the free version in their website: https://asprise.com/document-scan-upload-image-browser/web-scanner-source-code-open-order.html How can we try it? – Lamar Aug 18 '19 at 08:33
  • Plz mention somewhere that you are selling your commercial solution in the answer. This thread isn't about scanner.js. – Salik Apr 30 '20 at 08:06
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.

nafg
  • 2,424
  • 27
  • 25
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.

Mladen
  • 516
  • 1
  • 9
  • 20