Hi santosgernan1,
First request JavaScript code to embed the evaluation license into source codes of your web application.
Please follow the below steps:
1. Visit to VintaSoft User Portal at https://myaccount.vintasoft.com.
2. Click Register account now link if you do not have account in VintaSoft User Portal.
3. After successfull registration, Login to VintaSoft User Portal.
4. Then, select View Evaluation Licenses tab.
5. Click Request license for Windows development button in Request evaluation license for VintaSoft TWAIN .NET SDK section if you do not requested the evaluation license earlier.
6. Click Get JavaScript code for SDK registration button at the right side of information about evaluation license.
Note: Text with JavaScript code for SDK registration will be copied to the clipboard. So save it by pasting it in any text editor for further use.
Please follow the below steps to use the code.
1. Create a MVC project.
2. Add Data folder to the project folder.
Then, download the ZIP-archive with Windows installer of VintaSoft Web TWAIN service from https://www.vintasoft.com/zip/VintasoftWebTwainService-15.1.3.zip and copy the ZIP-archive to the Data folder.
Note: VintaSoft Web TWAIN service is a Windows service that provides Web API for accessing local TWAIN scanners for all users of local computer.
3. Create input type image and add the JavaScript code that acquires image from TWAIN scanner and displays scanned image on page.
HTML
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<style type="text/css">
body { font-family: Arial; font-size: 10pt; }
</style>
<script src="https://cdn.jsdelivr.net/npm/vintasoft-web-twain-js@15.1.3/dist/Vintasoft.Shared.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vintasoft-web-twain-js@15.1.3/dist/Vintasoft.Twain.min.js"></script>
</head>
<body>
<div style="text-align:center">
<h3>Preview of scanned image</h3>
<input type="image" id="previewImage" alt="Preview of scanned image" style="border:1px solid black; width:350px; height:350px" />
<br />
<br />
<a id="vintasoftWebTwainServiceInstallerLinkId" href="/Data/VintasoftWebTwainService-15.1.3.zip" hidden>Download installer of VintaSoft Web TWAIN service</a>
</div>
<script type="text/javascript">
window.onload = function () {
// acquire images from TWAIN scanner
__acquireImageFromTwainScanner();
};
function __acquireImageFromTwainScanner() {
// register the evaluation version of VintaSoft Web TWAIN service
// please read how to get evaluation license in documentation: https://www.vintasoft.com/docs/vstwain-dotnet-web/Licensing-Twain_Web-Evaluation.html
//Vintasoft.Twain.WebTwainGlobalSettingsJS.register('REG_USER', 'REG_URL', 'REG_CODE', 'EXPIRATION_DATE');
Vintasoft.Twain.WebTwainGlobalSettingsJS.register("USERNAME", "EMAIL", "CODE", "EXPIRYDATE");
// URL to the VintaSoft Web TWAIN service
var serviceUrl = 'https://localhost:25329/api/VintasoftTwainApi';
// a Web API controller that allows to work with TWAIN and SANE devices
var twainService = new Vintasoft.Shared.WebServiceControllerJS(serviceUrl);
// TWAIN device manager
var deviceManager = new Vintasoft.Twain.WebTwainDeviceManagerJS(twainService);
// the default settings of device manager
var deviceManagerInitSetting = new Vintasoft.Twain.WebTwainDeviceManagerInitSettingsJS();
try {
// open device manager
deviceManager.open(deviceManagerInitSetting);
}
catch (ex) {
if (ex.toString().startsWith('NetworkError')) {
document.getElementById('vintasoftWebTwainServiceInstallerLinkId').hidden = false;
alert("VintaSoft Web TWAIN service is not found.\n\nPlease close this dialog, link 'Download installer of VintaSoft Web TWAIN service' will appear at the top of this page, click the link, download VintaSoft Web TWAIN Service, manually install the service on your computer, reload this web page in web browser (Firefox must be restarted) and try to scan images once again.");
}
else
alert(ex);
return;
}
var device = null;
try {
// get the default TWAIN device
device = deviceManager.get_DefaultDevice();
// open device without UI
device.open(false);
// a collection that stores images, which are acquired from TWAIN/SANE devices and stored in memory of VintaSoft Web TWAIN service
var acquiredImages = new Vintasoft.Twain.WebAcquiredImageCollectionJS(deviceManager);
var acquireModalState;
do {
// do one step of modal image acquisition process
var acquireModalResult = device.acquireModalSync();
// get state of image acquisition
acquireModalState = acquireModalResult.get_AcquireModalState().valueOf();
switch (acquireModalState) {
case 2: // image is acquired
// get acquired image
var acquiredImage = acquireModalResult.get_AcquiredImage();
// add acquired image to the image collection
acquiredImages.add(acquiredImage);
// get image as Base64 string
var bitmapAsBase64String = acquiredImage.getAsBase64String();
// update image preview
var previewImageElement = document.getElementById('previewImage');
previewImageElement.src = bitmapAsBase64String;
// clear image collection (delete images from memory of VintaSoft Web TWAIN service) because image is not necessary anymore
acquiredImages.clear();
break;
case 4: // image scan is failed
alert(acquireModalResult.get_ErrorMessage());
break;
case 9: // image scan is finished
break;
}
}
while (acquireModalState !== 0);
}
catch (ex) {
alert(ex);
}
finally {
if (device != null) {
// close the device
device.close();
}
// close the device manager
deviceManager.close();
}
}
</script>
</body>
</html>
References:
https://www.vintasoft.com/docs/vstwain-dotnet-web/Programming-Twain_Web-Tutorials-Acquire_images_from_TWAIN_scanner_in_ASP.NET_MVC.html
https://www.vintasoft.com/docs/vstwain-dotnet-web/Licensing-Twain_Web-Evaluation.html