Dev Center
You can follow the steps below to use Dynamic Web TWAIN SDK to enable image capture from mobile cameras in a web page.
Firstly, please download and install Dynamic Web TWAIN if you haven’t done so.
Create a mobile-capture.html
and copy the Resources
folder of Dynamic Web TWAIN, which can be found under the installation folder, to the same location.
Embed the scripts of the library, among which dynamsoft.webtwain.addon.camera.js
is the add-on module for mobile web capture.
<script src="Resources/dynamsoft.webtwain.initiate.js"></script>
<script src="Resources/dynamsoft.webtwain.config.js"></script>
<script src="Resources/addon/dynamsoft.webtwain.addon.camera.js"></script>
Add an div
element on the page for the library. dwtcontrolContainer
is the default ID for the div. You can change it in the file dynamsoft.webtwain.config.js
if necessary.
<div id="dwtcontrolContainer"></div>
The below code shows how to scan a document from scanners on desktop and invoke the camera module for mobile capture.
function AcquireImage() {
if (DWObject) {
if (Dynamsoft.Lib.env.bMobile) {
var showVideoConfigs = {
scannerViewer:{
autoDetect:{
enableAutoDetect: true
}
},
filterViewer: {
exitDocumentScanAfterSave: true
}
};
if(!DWObject.UseLocalService) {
// invoke the camera module for mobile capture
DWObject.Addon.Camera.scanDocument(showVideoConfigs).then(
function(){
console.log("OK");
},
function(error){
console.log(error.message);
});
}
}
else {
DWObject.SelectSource(
function() {
DWObject.OpenSource();
DWObject.AcquireImage();
},
function() {
console.log("SelectSource failed!");
});
}
}
}
To try out the mobile web capture, please first deploy the web application in a HTTPS site so that it will get proper authentication to access the mobile cameras.
Here is a working mobile capture online demo which you can test.
By default, the size of the viewer is 270 in width and 350 in height, so it’ll appear to be too small. Check out how to customize the viewer for more information.
Important: Not all mobile browsers allow the use of cameras. Check out browsers on mobile devices for more information. If you are using an unsupported browser (for example, Chrome on iOS), you may receive the error The current browser has not implemented the MediaDevices interface
.
latest version