打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Web扫描识别控件Dynamic Web TWAIN使用实例:上传和扫描

Dynamic Web TWAIN是一个专为Web应用程序设计的TWAIN扫描识别控件,允许用户从扫描仪扫描文档或从数码相机/采集卡中获取图像,并支持上传和处理本地图像。本文将介绍如何通过TWAIN扫描识别工具Dynamic Web TWAIN实现在Web应用程序中扫描和上传文件

下载并安装Dynamic Web TWAIN后, 在 "\Dynamsoft\Dynamic Web TWAIN 9.0 Trial\Resources."目录下找到下列文件:

  • DynamicWebTWAIN.cab/ DynamicWebTWAINx64.cab – the ActiveX control edition for Internet Explorer (IE) 32 bit and 64 bit
  • DynamicWebTWAINPlugIn.msi - the Plugin Edition for Chrome, Firefox, Safari on Windows
  • DynamicWebTWAINMacEditionTrial.pkg – the Mac Edition for Chrome, Firefox, Safari on Mac OS X

将上述提到4个Dynamic Web TWAIN 插件文件复制并粘贴到MVC应用程序的Content文件夹中,从而将TWAIN扫描识别控件Dynamic Web TWAIN 嵌入到MVC应用程序。

Dynamic Web TWAIN文档扫描视图

如下面的截图所示,索引页上已添加了一个"Scan" 选项卡。点击 "Scan",用户将看到使用了Dynamic Web TWAIN插件的Scan.aspx页面。

启动Dynamic Web TWAIN

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function DW_CreateControl(bNeebBack) {
var objString = "";
var DWTContainer;
// For IE, render the ActiveX Object
if (DW_InIE) {
objString = "<object id='" + DW_ObjectName + "' style='width:" + DW_Width + "px;height:" + DW_Height + "px'";
if (DW_InWindowsX86)
objString += "codebase='" + DW_CABX86Path + "#version=" + DW_VersionCode + "' "; //load 32 bit CAB file for 32 bit Windows
else
objString += "codebase='" + DW_CABX64Path + "#version=" + DW_VersionCode + "' "; //load 64 bit CAB file for 64 bit Windows
var temp = DW_IsTrial ? DW_TRAILCLASSID : DW_FULLCLASSID;
objString += " classid='clsid:" + temp + "' viewastext>";
objString += " <param name='Manufacturer' value='DynamSoft Corporation' />";
objString += " <param name='ProductFamily' value='" + DW_ProductName + "' />";
objString += " <param name='ProductName' value='" + DW_ProductName + "' />";
//objString += " <param name='wmode' value='transparent'/> ";
objString += " </object>";
}
// For non-IE browsers, render the embed object
else {
objString = " <embed id='" + DW_ObjectName + "'style='display: inline; width:" + DW_Width + "px;height:" + DW_Height + "px' id='" + DW_ObjectName + "' type='" + DW_MIMETYPE + "'";
objString += " OnPostTransfer='Dynamsoft_OnPostTransfer' OnPostAllTransfers='Dynamsoft_OnPostAllTransfers'";
objString += " OnMouseClick='Dynamsoft_OnMouseClick' OnPostLoad='Dynamsoft_OnPostLoadfunction'";
objString += " OnImageAreaSelected = 'Dynamsoft_OnImageAreaSelected'";
objString += " OnImageAreaDeSelected = 'Dynamsoft_OnImageAreaDeselected'";
objString += " OnMouseDoubleClick = 'Dynamsoft_OnMouseDoubleClick'";
objString += " OnMouseRightClick = 'Dynamsoft_OnMouseRightClick'";
objString += " OnTopImageInTheViewChanged = 'Dynamsoft_OnTopImageInTheViewChanged'";
if (DW_InWindows)
objString += " pluginspage='" +
else
objString += " pluginspage='" + DW_PKGPath + "'></embed>"; //load the Mac edition for Chrome, Firefox, Safari on Mac
}
DWTContainer = document.getElementById(DW_DWTContainerID);
DWTContainer.innerHTML = objString;
DWObject = document.getElementById(DW_ObjectName);
}

扫描文档

通过TWAIN扫描识别控件可以从扫描仪中轻松捕获图像。下列JavaScript代码设置了像素类型,分辨率,扫描类型等。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
function AcquireImageInner() {
if (DW_DWTSourceContainerID == "")
DWObject.SelectSource();
else
DWObject.SelectSourceByIndex(document.getElementById(DW_DWTSourceContainerID).selectedIndex); //select from the available TWAIN devices
DWObject.CloseSource();
DWObject.OpenSource();
DWObject.IfShowUI = document.getElementById("ShowUI").checked;
var i;
for (i = 0; i < 3; i++) {
if (document.getElementsByName("PixelType").item(i).checked == true)
DWObject.PixelType = i;
} //set the pixel type of the image
DWObject.Resolution = Resolution.value;
DWObject.IfFeederEnabled = document.getElementById("ADF").checked; //whether scan from ADF or flatbed
DWObject.IfDuplexEnabled = document.getElementById("Duplex").checked; //whether do duplex scan
DWObject.IfDisableSourceAfterAcquire = true;
DWObject.AcquireImage(); //acquire images from the scanner
}

上传文档

将图像扫描至Dynamic Web TWAIN后,你可以通过HTTP Post方法,将扫描图像上传到Web服务器。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
var DW_ActionPage = "SaveToFile"; //call SaveToFile controller
function btnUpload_onclick(){
var i, strHTTPServer, strActionPage, strImageType;
strHTTPServer = DW_ServerName;
DWObject.HTTPPort = DW_strPort;
var CurrentPathName = unescape(location.pathname); // get current PathName in plain ASCII
var CurrentPath = CurrentPathName.substring(0, CurrentPathName.lastIndexOf("/") + 1);
strActionPage = CurrentPath + DW_ActionPage; //the ActionPage's file path
for(i=0;i<4;i++){
if(document.getElementsByName("ImageType").item(i).checked == true){
strImageType = i + 1;
break;
}
} //choose the image type, JPEG, TIFF, PNG or PDF
var uploadfilename = txt_fileName.value + "." + document.getElementsByName("ImageType").item(i).value;
if (strImageType == 2 && document.getElementById("MultiPageTIFF").checked) {
if ((DWObject.SelectedImagesCount == 1) || (DWObject.SelectedImagesCount == DWObject.HowManyImagesInBuffer)) {
DWObject.HTTPUploadAllThroughPostAsMultiPageTIFF(
strHTTPServer,
strActionPage,
uploadfilename
);
{
DWObject.HTTPUploadThroughPostAsMultiPageTIFF(
strHTTPServer,
strActionPage,
uploadfilename
);
}
} //whether to upload the images as a multi-page TIFF file
else if (strImageType == 4 && document.getElementById("MultiPagePDF").checked) {
if ((DWObject.SelectedImagesCount == 1) || (DWObject.SelectedImagesCount == DWObject.HowManyImagesInBuffer)) {
DWObject.HTTPUploadAllThroughPostAsPDF(
strHTTPServer,
strActionPage,
uploadfilename
);
}
else {
DWObject.HTTPUploadThroughPostAsMultiPagePDF(
strHTTPServer,
strActionPage,
uploadfilename
);
}
} //whether to upload the images as a multi-page PDF file
else {
DWObject.HTTPUploadThroughPostEx(
strHTTPServer,
DWObject.CurrentImageIndexInBuffer,
strActionPage,
uploadfilename,
strImageType
);
}

Controller.cs

?
1
2
3
4
5
6
7
8
9
10
11
public String SaveToFile()
{
String strImageName;
HttpFileCollectionBase files = Request.Files;
HttpPostedFileBase uploadfile = files["RemoteFile"];
strImageName = uploadfile.FileName;
uploadfile.SaveAs(Server.MapPath("~") + "\\UploadedImages\\" + strImageName);
return "";
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Dynamic Web TWAIN 安装
雅思口语 助你上8分的固定表达
PB动态报表格式自由定义的实现
如何通过网页来捕捉、编辑、上传图像 | Dynamic Web TWAIN
ABBYY FineReader参数不正确或无法打开TWAIN源
Hive动态分区
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服