How to Implement Document Management in Office 365 SharePoint

Nov 21, 2013

More and more organizations have moved to the Office 365 / SharePoint environment for document management. This article introduces how to integrate Dynamic Web TWAIN SDK into SharePoint client-side web parts.

Key Features of Dynamic Web TWAIN SDK

  • Provides ActiveX for working with 32 bit and 64 bit Internet Explorer.
  • Provides Plugin for working with Chrome, Firefox, Safari on Windows, macOS, and Linux
  • Capable of scanning images from scanners and other TWAIN compatible devices
  • Support for BMP, JPEG, PNG, single/multi-page PDF and single/multi-page TIFF
  • Supports cookie & session integration.
  • Downloads/Uploads image(s) through HTTP/HTTPS or FTP.
  • Supports JavaScript + HTML/HTML5 on the client side
  • No limit on the server-side platform/language. You can use ASP.NET, PHP, JSP, ASP, VB.NET, etc.

Developing Document Management Page for Office 365 SharePoint

According to Microsoft’s tutorial, we use following commands to initialize the skeleton of a new web part project:

mkdir helloworld
cd helloworld
npm install -g yo
npm install @microsoft/generator-sharepoint
yo @microsoft/sharepoint

Afterwards, we install Dynamic Web TWAIN via npm:

npm install dwt --save

Once the installation is done, we can import Dynamic Web TWAIN module to src/webparts/HelloWorldWebPart.ts as follows:

import Dynamsoft from 'dwt';
import { WebTwain } from 'dwt/dist/types/WebTwain';

The onInit() function is the appropriate place for initializing Dynamic Web TWAIN object:

  protected onInit(): Promise<void> {
    return super.onInit().then(_ => {
      // Initialize the WebTwain object
      Dynamsoft.DWT.Containers = [{ WebTwainId: 'dwtObject', ContainerId: this.containerId, Width: '300px', Height: '400px' }];
      Dynamsoft.DWT.RegisterEvent('OnWebTwainReady', () => { this.Dynamsoft_OnReady(); });                                                        
      Dynamsoft.DWT.ResourcesPath = '/dist';
      Dynamsoft.DWT.ProductKey = 'LICENSE-KEY';
      let checkScript = () => {
        if (Dynamsoft.Lib.detect.scriptLoaded) {
        } else {
          setTimeout(() => checkScript(), 100);

  public Dynamsoft_OnReady(): void {
    this.DWObject = Dynamsoft.DWT.GetWebTwain(this.containerId);
    this.bWASM = Dynamsoft.Lib.env.bMobile || !Dynamsoft.DWT.UseLocalService;

Here, a valid license is required to make the SDK work. The resource path points to the CSS, JS and installer files of Dynamic Web TWAIN, which can be found at node_modules/dwt/dist. In order to load them successfully, we add the following code snippet in gulpfile.js to copy these assets to the directory we set:

let resCopy = build.subTask('resCopy', (gulp, buildOptions, done) => {

Finally, we add a button and its corresponding function for scanning documents:

public render(): void {
    this.domElement.innerHTML = `
      <div class="${ styles.helloWorld }">
        <div class="${ styles.container }">
          <div class="${ styles.row }">
            <div class="${ styles.column }">
              <span class="${ styles.title }">Welcome to SharePoint!</span>
              <p class="${ styles.subTitle }">Customize SharePoint experiences using Web Parts.</p>
              <p class="${ styles.description }">${escape(}</p>
              <button class="${ styles.button } id="scan">Scan</button>
              <div id="${this.containerId}"></div>
      this.button = this.domElement.querySelector('button');
      this.button.addEventListener('click', this.acquireImage.bind(this));

  public acquireImage(): void {
    if (!this.DWObject)
      this.DWObject = Dynamsoft.DWT.GetWebTwain();
    if (this.bWASM) {
      alert("Scanning is not supported under the WASM mode!");
    else if (this.DWObject.SourceCount > 0) {
      const onAcquireImageSuccess = () => { this.DWObject.CloseSource(); };
      const onAcquireImageFailure = onAcquireImageSuccess;
      this.DWObject.AcquireImage({}, onAcquireImageSuccess, onAcquireImageFailure);
    } else {
      alert("No Source Available!");

Now, enter the following command to build and preview your web part:

gulp serve

Web TWAIN for scanning document in SharePoint

Source Code

yushulx/sharepoint-web-twain-document-scan (

Subscribe Newsletter

Subscribe to our mailing list to get the monthly update.