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

111 lines (93 loc) 4.67 kB
<!DOCTYPE html> <html> <head> <title>Use Dynamic Web TWAIN's Editing features</title> <script src="../dist/dynamsoft.webtwain.min.js"></script> </head> <body style="padding: 30px;"> <input type="button" style="font-size: x-large;" value="Scan" onclick="AcquireImage();" /> <input type="button" style="font-size: x-large;" value="Load" onclick="LoadImage();" /> <input type="button" style="font-size: x-large;" value="Rotate Left" onclick="RotateLeft();" /> <input type="button" style="font-size: x-large;" value="Rotate Right" onclick="RotateRight();" /> <input type="button" style="font-size: x-large;" value="Mirror" onclick="Mirror();" /> <input type="button" style="font-size: x-large;" value="Flip" onclick="Flip();" /> <input type="button" style="font-size: x-large;" value="Show Image Editor" onclick="ShowImageEditor();" /> <br /> <br /> <!-- dwtcontrolContainer is the default div id for Dynamic Web TWAIN control. If you need to rename the id, you should also change the id in the dynamsoft.webtwain.config.js accordingly. --> <div id="dwtcontrolContainer"></div> <script type="text/javascript"> Dynamsoft.DWT.ResourcesPath = "../dist"; Dynamsoft.DWT.ProductKey = 't0078lQAAAA6/IlIbNC7kmlEwnoekMXbQCjKCIbXQPNX5YcTlkQ1q4R4g+O1GT800Pmu8OKFOEv81ye/RJPXBdG9de9pkHxXgXq2nohPqqh9G'; window.onload = function () { Dynamsoft.DWT.Containers = [{ContainerId:'dwtcontrolContainer', Width:700, Height:800}]; Dynamsoft.DWT.Load(); }; var console = window['console'] ? window['console'] : { 'log': function () { } }; 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 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' } function AcquireImage() { if (DWObject) { DWObject.SelectSource(function () { var OnAcquireImageSuccess, OnAcquireImageFailure; OnAcquireImageSuccess = OnAcquireImageFailure = function () { DWObject.CloseSource(); }; DWObject.OpenSource(); DWObject.IfDisableSourceAfterAcquire = true; // Scanner source will be disabled/closed automatically after the scan. DWObject.AcquireImage(OnAcquireImageSuccess, OnAcquireImageFailure); }, function () { console.log('SelectSource failed!'); }); } } //Callback functions for async APIs function OnSuccess() { console.log('successful'); } function OnFailure(errorCode, errorString) { alert(errorString); } function LoadImage() { if (DWObject) { DWObject.IfShowFileDialog = true; // Open the system's file dialog to load image DWObject.LoadImageEx("", Dynamsoft.DWT.EnumDWT_ImageType.IT_ALL, OnSuccess, OnFailure); // Load images in all supported formats (.bmp, .jpg, .tif, .png, .pdf). OnSuccess or OnFailure will be called after the operation } } function RotateLeft() { if (DWObject) if (DWObject.HowManyImagesInBuffer > 0) DWObject.RotateLeft(DWObject.CurrentImageIndexInBuffer); } function RotateRight() { if (DWObject) if (DWObject.HowManyImagesInBuffer > 0) DWObject.RotateRight(DWObject.CurrentImageIndexInBuffer); } function Mirror() { if (DWObject) if (DWObject.HowManyImagesInBuffer > 0) DWObject.Mirror(DWObject.CurrentImageIndexInBuffer); } function Flip() { if (DWObject) if (DWObject.HowManyImagesInBuffer > 0) DWObject.Flip(DWObject.CurrentImageIndexInBuffer); } function ShowImageEditor() { if (DWObject) { if (DWObject.HowManyImagesInBuffer == 0) alert("There is no image in buffer."); else{ var imageEditor = DWObject.Viewer.createImageEditor(); imageEditor.show(); } } } </script> </body> </html>