DEV Community

Xiao Ling
Xiao Ling

Posted on • Originally published at dynamsoft.com

1

How to Implement Document Management in Office 365 SharePoint

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.

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
Enter fullscreen mode Exit fullscreen mode

Afterwards, we install Dynamic Web TWAIN via npm:

npm install dwt --save
Enter fullscreen mode Exit fullscreen mode

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';
Enter fullscreen mode Exit fullscreen mode

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) {
          Dynamsoft.DWT.Load();
        } else {
          setTimeout(() => checkScript(), 100);
        }
      };
      checkScript();
    });
  }

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

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) => {
  gulp.src('./node_modules/dwt/dist/**.*')
    .pipe(gulp.dest('./dist/'));
  gulp.src('./node_modules/dwt/dist/dist/**.*')
    .pipe(gulp.dest('./dist/dist'));
  gulp.src('./node_modules/dwt/dist/addon/**.*')
    .pipe(gulp.dest('./dist/addon'));
  gulp.src('./node_modules/dwt/dist/src/**.*')
    .pipe(gulp.dest('./dist/src'));
  done();
})
build.rig.addPreBuildTask(resCopy);
Enter fullscreen mode Exit fullscreen mode

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(this.properties.description)}</p>
              <button class="${ styles.button } id="scan">Scan</button>
              <div id="${this.containerId}"></div>
            </div>
          </div>
        </div>
      </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.OpenSource();
      this.DWObject.AcquireImage({}, onAcquireImageSuccess, onAcquireImageFailure);
    } else {
      alert("No Source Available!");
    }
  }
Enter fullscreen mode Exit fullscreen mode

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

gulp serve
Enter fullscreen mode Exit fullscreen mode

sharepoint web document management

Source Code

https://github.com/yushulx/sharepoint-web-twain-document-scan

Image of AssemblyAI tool

Transforming Interviews into Publishable Stories with AssemblyAI

Insightview is a modern web application that streamlines the interview workflow for journalists. By leveraging AssemblyAI's LeMUR and Universal-2 technology, it transforms raw interview recordings into structured, actionable content, dramatically reducing the time from recording to publication.

Key Features:
🎥 Audio/video file upload with real-time preview
🗣️ Advanced transcription with speaker identification
⭐ Automatic highlight extraction of key moments
✍️ AI-powered article draft generation
📤 Export interview's subtitles in VTT format

Read full post

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay