Introduction
This article talks about how to use Dynamic Web TWAIN ActiveX
control with Internet Explorer Protected Mode.
Background
Since Internet Explorer 7 on
Windows Vista was released, Protected Mode has been introduced as a new
security feature. It is based on Windows Vista’s new access control security
mechanism. When running in Protected Mode, Internet Explorer is a low
integrity process and has limited permissions to access the user system.
While Protected Mode better
protects the system from the Internet, it causes problems when ActiveX needs to
talk with high integrity objects.
Dynamsoft’s Dynamic Web
TWAIN is a document scanning SDK for web
applications. You can embed Dynamic Web TWAIN in your website to enable users
scan documents online. It includes an ActiveX edition which allows users to
acquire images from TWAIN compatible scanners within IE (x86/x64). When running
Dynamic Web TWAIN on Windows Vista and above, IE Protected Mode is on by
default so users consistently get issues like the following:
-
ActiveX failed to access the scanners
connected to the user machine
-
IE crashed when ActiveX tries to acquire
images from scanner due to insufficient permissions
One possible solution is to have
the end users manually turn off Protected Mode themselves in order to make
ActiveX control work properly, but this is inconvenient and not user friendly.
Working with Protected
Mode
To solve the issues caused by Protected Mode, Dynamsoft has
introduced a new approach. Instead of running the ActiveX under the browser
process, which has low level access, Dynamic Web TWAIN uses an independent
broker process to communicate with the scanners for better compatibility and
robustness. The broker process has medium level permission so it can access
medium integrity objects. It has the following benefits:
- Avoid browser crashes caused by scanner driver problems,
thus improving the robustness of the web application. The independent process
will not affect the browser process.
- The independent process used for scanning has a higher
permission level than the browser process. This can solve the scanning issues, such
as browsers not accessing the scanner source successfully, caused by the
increased security features of Windows/IE.
Using the Code
You can simply set the BrokerProcessType
Property to 1 to
enable separate broker process for scanning. Below is a simple sample of doing
ADF scanning, with resolution 100 and using gray color in browser using Dynamic
Web TWAIN.
window.onload = DW_Pageonload;
function DW_PageonloadInner() { ua = (navigator.userAgent.toLowerCase());
if (ua.indexOf("msie") != -1)
DW_InIE = true;
else
DW_InIE = false;
if (ua.indexOf("macintosh") != -1)
DW_InWindows = false;
else
DW_InWindows = true;
if (ua.indexOf("win64") != -1 && ua.indexOf("x64") != -1)
DW_InWindowsX86 = false;
else
DW_InWindowsX86 = true;
}
function DW_CreateControl() {
var objString = "";
var DWTContainer;
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 + "' ";
else
objString += "codebase='" + DW_CABX64Path + "#version=" + DW_VersionCode + "' ";
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 += " </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'";
objString += " OnGetFilePath='Dynamsoft_OnGetFilePath'";
if (DW_InWindows)
objString += " pluginspage='" + DW_MSIPath + "'></embed>";
else
objString += " pluginspage='" + DW_PKGPath + "'></embed>";
}
DWTContainer = document.getElementById(DW_DWTContainerID);
DWTContainer.innerHTML = objString;
DWObject = document.getElementById(DW_ObjectName);
}
function DW_Pageonload() {
DW_PageonloadInner(); InitInfo(); DW_CreateControl();
vShowNoControl = false; DW_Seed = setInterval(DW_ControlDetect, 500);
}
function DW_ControlDetect() {
if (DWObject.ErrorCode == 0) {
DWObject.ProductKey = "391243D92C15C4BE5C77E6EC25D16FC6D9754433530E517A67371A97AD158D173373ABC58E8272C940F1ACE1E97C953920000000";
DWObject.BrokerProcessType = 1; DW_Pause();
if (DW_InIE) {
DWObject.attachEvent('OnPostTransfer', Dynamsoft_OnPostTransfer);
DWObject.attachEvent('OnPostAllTransfers', Dynamsoft_OnPostAllTransfers);
DWObject.attachEvent('OnMouseClick', Dynamsoft_OnMouseClick);
DWObject.attachEvent('OnPostLoad', Dynamsoft_OnPostLoadfunction);
DWObject.attachEvent('OnImageAreaSelected', Dynamsoft_OnImageAreaSelected);
DWObject.attachEvent('OnMouseDoubleClick', Dynamsoft_OnMouseDoubleClick);
DWObject.attachEvent('OnMouseRightClick', Dynamsoft_OnMouseRightClick);
DWObject.attachEvent('OnTopImageInTheViewChanged', Dynamsoft_OnTopImageInTheViewChanged);
DWObject.attachEvent('OnImageAreaDeSelected', Dynamsoft_OnImageAreaDeselected);
DWObject.attachEvent('OnGetFilePath', Dynamsoft_OnGetFilePath);
}
}
else {
if (vShowNoControl == false) {
DW_NoControl();
vShowNoControl = true;
}
}
DW_Timeout = setTimeout(function () { }, 10);
}
function DW_Pause() {
clearInterval(DW_Seed);
}
function DW_NoControl() {
DW_CreateNonInstallDivPlugin();
document.getElementById(DW_DWTNonInstallContainerID).style.display = "inline";
document.getElementById(DW_DWTContainerID).style.display = "none";
}
function DW_CreateNonInstallDivPlugin() {
var varHref = "";
if (DW_InIE) {
var ObjString = "<div style='display: block; border:solid black 1px; text-align:center; width:" + DW_Width + "px;height:" + DW_Height + "px'>";
ObjString += "<ul style='padding-top:100px;'>";
ObjString += "<li>The Component is not installed</li>";
ObjString += "<li>You need to download and install the ActiveX to use this sample.</li>";
ObjString += "<li>Please follow the instructions in the information bar.</li>";
ObjString += "</ul></div>";
}
else {
if (DW_InWindows) {
if (location.hostname != "")
varHref = "http://" + location.host + location.pathname.substring(0, location.pathname.lastIndexOf('/')) + "/" + DW_MSIPath;
else
varHref = DW_MSIPath;
}
else {
if (location.hostname != "")
varHref = "http://" + location.host + location.pathname.substring(0, location.pathname.lastIndexOf('/')) + "/" + DW_PKGPath;
else
varHref = DW_PKGPath;
}
var ObjString = "<div style='display: block; border:solid black 1px; text-align:center; width:" + DW_Width + "px;height:" + DW_Height + "px'>";
ObjString += "<ul style='padding-top:100px;'>";
ObjString += "<li>The Component is not installed</li>";
ObjString += "<li>You need to download and install the plug-in to use this sample.</li>";
ObjString += "<li>Please click the below link to download it.</li>";
ObjString += "<li>After the installation, please RESTART your browser.</li>";
ObjString += "<li><a href='" + varHref + "'>Download</a></li>";
ObjString += "</ul></div>";
}
document.getElementById(DW_DWTNonInstallContainerID).innerHTML = ObjString;
}
function DW_AcquireImage() {
DWObject.SelectSource(); DWObject.OpenSource();
DWObject.IfShowUI = false; DWObject.PixelType = 1; DWObject.Resolution = 100; DWObject.IfFeederEnabled = true;
DWObject.XferCount = -1;
DWObject.IfAutoFeed = true; DWObject.IfDisableSourceAfterAcquire = true;
DWObject.AcquireImage();
}
When you run the web application embedding Dynamic Web
TWAIN, you will see the broker process for scanning in Task Manager:
Conclusion
By using an independent broker process for scanning in
Dynamic Web TWAIN 9.0, it greatly improves the security and robustness of the
web scanning application. And users will find it easier and smoother to
activate and use the ActiveX control for web scanning on higher versions of IE
on Windows.
For more information about Dynamic Web TWAIN, visit the Dynamsoft
website.
Resources
Dynamic Web TWAIN is a client-side web scanning control which
you can embed into your web application. It allows users to scan documents from
TWAIN compatible scanners or acquiring images from digital cameras.
Dynamic Web TWAIN supports all the mainstream browsers on
Windows and Mac.
ActiveX Edition – work with x84/x64 IE
Plugin Edition – work with Chrome, Firefox, Safari, Opera on Windows
Mac Edition - work with Chrome, Firefox, Safari, Opera on Mac