UNPKG

dwt

Version:

Dynamic Web TWAIN is a TWAIN/ICA/SANE-based scanning SDK software specifically designed for web applications running on Windows/macOS/Linux. With just a few lines of code, you can develop robust applications to scan documents from TWAIN/ICA/SANE-compatibl

98 lines (89 loc) 3.59 kB
<!DOCTYPE html> <html> <head> <title>Custom Scan</title> <script src="../dist/dynamsoft.webtwain.min.js"></script> </head> <body style="padding: 30px;"> <div id="scanOptions"> <label for="BW" > <input type="radio" value="0" name="PixelType">B&amp;W </label> <label for="Gray"> <input type="radio" value="1" name="PixelType">Gray</label> <label for="RGB"> <input type="radio" value="2" name="PixelType" checked="checked">Color</label> | <label> <input type="checkbox" id="ADF" checked="checked">Auto Feeder</label> <label> <input type="checkbox" id="ShowUI" checked="checked">Show UI <br /> </label> <select id="Resolution"> <option value="100">100</option> <option value="150">150</option> <option value="200">200</option> <option value="300">300</option> </select> <select id="source" style="position: relative; width: 220px;"></select> <input type="button" value="Scan" onclick="AcquireImage();" /> </div> <input type="button" id="mobileFile" value="Acquire" style="font-size: x-large;display:none" onclick="LoadImage()" /> <br /> <div id="dwtcontrolContainer"></div> <script type="text/javascript"> Dynamsoft.DWT.ResourcesPath = "../dist"; Dynamsoft.DWT.ProductKey = 't0078lQAAAA6/IlIbNC7kmlEwnoekMXbQCjKCIbXQPNX5YcTlkQ1q4R4g+O1GT800Pmu8OKFOEv81ye/RJPXBdG9de9pkHxXgXq2nohPqqh9G'; Dynamsoft.DWT.RegisterEvent('OnWebTwainReady', Dynamsoft_OnReady); // Register OnWebTwainReady event. This event fires as soon as Dynamic Web TWAIN is initialized and ready to be used window.onload = function () { if (Dynamsoft.Lib.env.bMobile) { document.getElementById('scanOptions').style.display = "none"; document.getElementById('mobileFile').style.display = ""; } Dynamsoft.DWT.Containers = [{ContainerId:'dwtcontrolContainer', Width:600, Height:800}]; Dynamsoft.DWT.Load(); }; var DWObject; function Dynamsoft_OnReady() { DWObject = Dynamsoft.DWT.GetWebTwain('dwtcontrolContainer'); // Get the Dynamic Web TWAIN object that is embeded in the div with id 'dwtcontrolContainer' if (DWObject) { var count = DWObject.SourceCount; for (var i = 0; i < count; i++) document.getElementById("source").options.add(new Option(DWObject.GetSourceNameItems(i), i)); } } function AcquireImage() { if (DWObject) { DWObject.SelectSourceByIndex(document.getElementById("source").selectedIndex); DWObject.OpenSource(); var pixelType = 2; var pixelTypeInputs = document.getElementsByName("PixelType"); for (var i = 0; i < pixelTypeInputs.length; i++) { if (pixelTypeInputs[i].checked) { pixelType = pixelTypeInputs[i].value; break; } } DWObject.AcquireImage( { IfShowUI: document.getElementById("ShowUI").checked, IfFeederEnabled: document.getElementById("ADF").checked, PixelType: pixelType, Resolution: parseInt(document.getElementById("Resolution").value), IfDisableSourceAfterAcquire: true }, function () { console.log("Successful!"); }, function (settings, errCode, errString) { alert(errString) } ); } } function LoadImage() { DWObject.LoadImageEx('', 5); } </script> </body> </html>