Javascript 如何从浏览器触发扫描仪?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/3504231/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How Can I Trigger a Scanner from a Browser?
提问by Randy J Parker
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.
我有富士通 fi-6130 TWAIN / ISIS 扫描仪,我想通过 jQuery Rails 网页中的按钮触发它。我不仅想让页面告诉扫描仪“去”,我还想在扫描(单个)页面后通过 Paperclip 上传结果文件 - 理想情况下不需要用户导航文件浏览器小部件手动查找文件。
Each scanner is usb attached to a Windows XP desktop, though we may replace these call center desktops with Google Chrome OS.
每个扫描仪都通过 USB 连接到 Windows XP 桌面,但我们可能会将这些呼叫中心桌面替换为 Google Chrome 操作系统。
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)
这个问题是大约一年前提出的,但主要收到的建议是需要使用价值数百美元的商业 IE .NET 产品 -从 webapp 与最终用户的扫描仪接口(网络/扫描仪集成)
回答by Basic
This isn't possible from directly within a standard HTML/js page - js has no permissions to access peripherals like scanners.
这在标准 HTML/js 页面中是不可能的 - js 没有访问外围设备(如扫描仪)的权限。
It may well be possible using either flash or silverlight but suspect you'd hit permissions issues. There's articles hereand herebut it may be a) too involved and b) not quite what you're after.
很可能使用 flash 或 silverlight,但怀疑您遇到了权限问题。这里和这里都有文章,但它可能 a) 太复杂 b) 不是你想要的。
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
如果您控制 Web 应用程序将在其上运行的机器,我建议使用简单的桌面客户端来执行扫描并允许通过打开本地端口从网页内连接到它
so js does an AJAX call to (say) http://localhost:1234/Services/Scanwhich returns an image
所以 js 对(比如)http://localhost:1234/Services/Scan进行 AJAX 调用,它返回一个图像
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...)
编辑:关于编写桌面客户端,您有多种选择。我个人建议您不要尝试在 PERL/PHP 中执行此操作,因为它们似乎不是完成这项工作的正确工具,我怀疑您最终会加载 COM 对象来尝试访问 TWAIN 设备(我们都知道这有多有趣...)
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.
在评论中,你已经表明你不喜欢 Visual Studio - 所以如果你熟悉 Java,我建议你看看JTwain(商业但似乎质量很好)或从这里开始阅读。注意:我不是一个经常使用 Java 开发人员的人,所以不能保证以上任何一个都是您所需要的。
Beyond that, I'd suggest C++ using a different IDE (although this wouldn't be OS-agnostic)
除此之外,我建议 C++ 使用不同的 IDE(尽管这与操作系统无关)
回答by Steven J. Garner
There is a solution called Dynamic Web TWAIN from Dynamsoftwhich provides a Browser-based TWAIN SDK for acquiring images from TWAIN devices, and editing and saving them to remote databases.
Dynamsoft有一个名为Dynamic Web TWAIN的解决方案,它提供了一个基于浏览器的 TWAIN SDK,用于从 TWAIN 设备获取图像,并将它们编辑并保存到远程数据库。
回答by Mladen
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.
似乎有一个适用于富士通 fi 系列扫描仪的 Web API 工具包。它基本上是一个安装在客户端机器上的应用程序,其中扫描仪通过 JSON 或 Silverlight 接受调用并将它们发送到扫描仪驱动程序。
http://uk.emc.com/enterprise-content-management/captiva/cloud-toolkit.htm
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.
我刚刚下载了它并且正在阅读文档,所以不能保证它有效。
回答by Asprise Support
As @Basic mentioned, JTwaincan 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:
正如@Basic所提到的,JTwain可用于创建这样的解决方案。事实上,JTwain 的开发者已经创建了ScannerJS,它允许使用 JavaScript 直接从 IE、Chrome 和 Firefox 等浏览器进行扫描。为了在您的网页中使用它,您需要:
Include scanner.js:
包括scanner.js:
<html lang="en"><head>
<script src="//asprise.azureedge.net/scannerjs/scanner.js" type="text/javascript"></script>
and call scanner.scan:
并致电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
        }
    }
]
}
    );
    }
回答by nafg
回答by Abu Ayyub
actually you can use my app (only work on windows)
实际上你可以使用我的应用程序(仅适用于 Windows)

