VintaSoft Twain .NET SDK 15.4: Документация для Веб разработчика
В этом разделе
Как сканировать страницы с помощью автоматического устройства подачи документов (ADF) TWAIN/WIA/SANE/eSCL сканера?
В этом разделе
Функция WebTwainDeviceJS.get_HasFeeder позволяет получить значение, указывающее, есть ли у устройства TWAIN/WIA/SANE/eSCL устройство автоматической подачи документов.
Функция WebTwainDeviceJS.get_HasDuplex позволяет получить значение, указывающее, поддерживает ли устройство автоматической подачи документов устройства TWAIN/WIA/SANE/eSCL режим дуплекса.

Если вы хотите сканировать страницы с помощью устройства автоматической подачи документов (АПД) сканера изображений TWAIN/WIA/eSCL, необходимо включить устройство автоматической подачи документов сканера изображений TWAIN/WIA/SANE/eSCL. Функция WebTwainDeviceJS.get_IsFeederEnabled позволяет получить значение, указывающее на то, что устройство подачи документов устройства TWAIN/WIA/SANE/eSCL включено. Функция WebTwainDeviceJS.set_IsFeederEnabled позволяет установить значение, указывающее на то, что устройство подачи документов устройства TWAIN/WIA/SANE/eSCL включено.


Вот JavaScript код, который демонстрирует как использовать устройство подачи документов TWAIN/WIA/SANE/eSCL сканера изображений:
// acquire images from document feeder of TWAIN/WIA/SANE/eSCL image scanner
__acquireImagesFromDocumentFeederOfTwainScanner();



/**
 * Acquires images from document feeder of TWAIN/WIA/SANE/eSCL image scanner.
 */
function __acquireImagesFromDocumentFeederOfTwainScanner() {
    // register the evaluation version of VintaSoft Web TWAIN service
    // please read how to get evaluation license in documentation: https://www.vintasoft.ru/docs/vstwain-dotnet-web/Licensing-Twain_Web-Evaluation.html
    Vintasoft.Twain.WebTwainGlobalSettingsJS.register('REG_USER', 'REG_URL', 'REG_CODE', 'EXPIRATION_DATE');

    // URL to the VintaSoft Web TWAIN service
    var serviceUrl = 'https://localhost:25329/api/VintasoftTwainApi';
    // a Web API controller that allows to work with TWAIN/WIA/SANE/eSCL devices
    var twainService = new Vintasoft.Shared.WebServiceControllerJS(serviceUrl);

    // TWAIN/WIA/SANE/eSCL device manager
    var deviceManager = new Vintasoft.Twain.WebTwainDeviceManagerJS(twainService);

    // the default settings of device manager
    var deviceManagerInitSetting = new Vintasoft.Twain.WebTwainDeviceManagerInitSettingsJS();

    var device = null;
    try {
        // open device manager
        deviceManager.open(deviceManagerInitSetting);

        // get the TWAIN device
        device = deviceManager.findDeviceByName("Twain64: KODAK Scanner: i5000");
        if (device == null)
            return;

        // open device without UI
        device.open(false);

        // if device is SANE device
        if (device.get_IsSane()) {
            // specify that images must be acquired from ADF
            device.set_SaneScanSource("ADF Duplex");
        }
        // if device is TWAIN/WIA/eSCL device
        else {
            // if device has the automatic document feeder
            if (device.get_HasFeeder()) {
                // enable the automatic document feeder of TWAIN/WIA/eSCL device
                device.set_IsFeederEnabled(true);

                // if automatic document feeder of TWAIN/WIA/eSCL device can work in duplex mode
                if (device.get_HasDuplex()) {
                    // enable duplex scanning
                    device.set_IsDuplexEnabled(true);
                }
            }
        }

        // a collection that stores images, which are acquired from TWAIN/WIA/SANE/eSCL 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();
    }
}



Вот TypeScript код, который демонстрирует как использовать устройство подачи документов TWAIN/WIA/SANE/eSCL сканера изображений:
import { Component } from '@angular/core';

@Component({
  selector: 'twain-scanning-demo',
  templateUrl: './twain-scanning-demo.component.html'
})
export class TwainScanningDemoComponent {

  ngOnInit() {
    // acquire images from document feeder of TWAIN/WIA/SANE/eSCL image scanner
    __acquireImagesFromDocumentFeederOfTwainScanner();
  }


  /**
   * Acquires images from document feeder of TWAIN/WIA/SANE/eSCL image scanner.
   */
  __acquireImagesFromDocumentFeederOfTwainScanner() {
    // register the evaluation version of VintaSoft Web TWAIN service
    // please read how to get evaluation license in documentation: https://www.vintasoft.ru/docs/vstwain-dotnet-web/Licensing-Twain_Web-Evaluation.html
    Vintasoft.Twain.WebTwainGlobalSettingsJS.register('REG_USER', 'REG_URL', 'REG_CODE', 'EXPIRATION_DATE');

    // URL to the VintaSoft Web TWAIN service
    let serviceUrl: string = 'https://localhost:25329/api/VintasoftTwainApi';
    // a Web API controller that allows to work with TWAIN/WIA/SANE/eSCL devices
    let twainService: Vintasoft.Shared.WebServiceControllerJS = new Vintasoft.Shared.WebServiceControllerJS(serviceUrl);

    // TWAIN device manager
    let deviceManager: Vintasoft.Twain.WebTwainDeviceManagerJS = new Vintasoft.Twain.WebTwainDeviceManagerJS(twainService);

    // the default settings of device manager
    let deviceManagerInitSetting: Vintasoft.Twain.WebTwainDeviceManagerInitSettingsJS = new Vintasoft.Twain.WebTwainDeviceManagerInitSettingsJS();

    try {
      // open device manager
      deviceManager.open(deviceManagerInitSetting);
    }
    catch (ex) {
      alert(ex);
      return;
    }

    let device: Vintasoft.Twain.WebTwainDeviceJS = null;
    try {
      // get the TWAIN device
      device = deviceManager.findDeviceByName("Twain64: KODAK Scanner: i5000");
      if (device == null)
        return;

      // open device without UI
      device.open(false);

      // if device is SANE device
      if (device.get_IsSane()) {
        // specify that images must be acquired from ADF
        device.set_SaneScanSource("ADF Duplex");
      }
      // if device is TWAIN/WIA/eSCL device
      else {
        // if device has the automatic document feeder
        if (device.get_HasFeeder()) {
          // enable the automatic document feeder of TWAIN/WIA/eSCL device
          device.set_IsFeederEnabled(true);

          // if automatic document feeder can work in duplex mode
          if (device.get_HasDuplex()) {
            // enable the duplex scanning
            device.set_IsDuplexEnabled(true);
          }
        }
      }

      // a collection that stores images, which are acquired from TWAIN/WIA/SANE/eSCL devices and stored in memory of VintaSoft Web TWAIN service
      let acquiredImages: Vintasoft.Twain.WebAcquiredImageCollectionJS = new Vintasoft.Twain.WebAcquiredImageCollectionJS(deviceManager);
      let acquireModalState: number;
      do {
        // do one step of modal image acquisition process
        let acquireModalResult: Vintasoft.Twain.WebTwainDeviceAcquireModalResultJS = device.acquireModalSync();
        // get state of image acquisition
        acquireModalState = acquireModalResult.get_AcquireModalState().valueOf() as number;

        switch (acquireModalState) {
          case 2:   // image is acquired
            // get acquired image
            let acquiredImage: Vintasoft.Twain.WebAcquiredImageJS = acquireModalResult.get_AcquiredImage();
            // add acquired image to the image collection
            acquiredImages.add(acquiredImage);

            // get image as Base64 string
            let bitmapAsBase64String: string = acquiredImage.getAsBase64String();
            // update image preview
            let previewImageElement: HTMLImageElement = document.getElementById('previewImage') as HTMLImageElement;
            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();
    }
  }

}