11import { Component , OnInit } from '@angular/core' ;
22import Dynamsoft from 'dwt' ;
3+ import { WebTwain } from 'dwt/dist/types/WebTwain' ;
4+ import { Device } from 'dwt/dist/types/WebTwain.Acquire' ;
35import { DDV , EditViewer , IDocument , UiConfig } from 'dynamsoft-document-viewer' ;
46
57@Component ( {
@@ -10,8 +12,8 @@ import { DDV, EditViewer, IDocument, UiConfig } from 'dynamsoft-document-viewer'
1012export class DocumentViewerComponent implements OnInit {
1113 editViewer ?: EditViewer ;
1214 dropdown ?: HTMLElement ;
13- dwtObject ?: any = null ;
14- sourceList = [ ] ;
15+ dwtObject ?: WebTwain ;
16+ sourceList ?: Device [ ] ;
1517 acquireDocumentButton : HTMLElement | null = null ;
1618 cancelCaptureButton : HTMLElement | null = null ;
1719 currentDoc ?: IDocument ;
@@ -120,8 +122,13 @@ export class DocumentViewerComponent implements OnInit {
120122 ngOnDestroy ( ) {
121123 // Unload Dynamic Web TWAIN
122124 if ( this . dwtObject ) {
123- Dynamsoft . DWT . DeleteDWTObject ( this . dwtObject . _id ) ;
124- this . dwtObject = null ;
125+ Dynamsoft . DWT . Unload ( ) ;
126+ this . dwtObject = undefined ;
127+ }
128+
129+ if ( this . editViewer ) {
130+ this . editViewer . destroy ( ) ;
131+ this . editViewer = undefined ;
125132 }
126133 }
127134 ngOnInit ( ) {
@@ -146,16 +153,21 @@ export class DocumentViewerComponent implements OnInit {
146153 } ) ;
147154 this . editViewer . displayMode = "single" ;
148155 this . editViewer . on ( "toggleDropdown" , this . toggleDropdown ) ;
156+ Dynamsoft . DWT . AutoLoad = false ;
157+ Dynamsoft . DWT . Containers = [ { WebTwainId : "dwtObj" } ]
158+ Dynamsoft . DWT . Load ( ) ;
159+ Dynamsoft . DWT . RegisterEvent ( "OnWebTwainReady" , ( ) => {
160+ this . dwtObject = Dynamsoft . DWT . GetWebTwain ( "dwtObj" ) as WebTwain ;
161+ } )
162+ // Dynamsoft.DWT.CreateDWTObjectEx({ "WebTwainId": "container" }, (obj) => {
163+ // this.dwtObject = obj;
149164
150- Dynamsoft . DWT . CreateDWTObjectEx ( { "WebTwainId" : "container" } , ( obj ) => {
151- this . dwtObject = obj ;
152-
153- this . dwtObject . Viewer . bind ( document . createElement ( "div" ) ) ;
154- this . dwtObject . Viewer . width = 640 ;
155- this . dwtObject . Viewer . height = 640 ;
156- } , ( errorString ) => {
157- console . log ( errorString ) ;
158- } ) ;
165+ // this.dwtObject.Viewer.bind(document.createElement("div"));
166+ // this.dwtObject.Viewer.width = 640;
167+ // this.dwtObject.Viewer.height = 640;
168+ // }, (errorString) => {
169+ // console.log(errorString);
170+ // });
159171
160172 // Bind scan popup buttons after DOM is ready
161173 setTimeout ( ( ) => {
@@ -181,7 +193,7 @@ export class DocumentViewerComponent implements OnInit {
181193 }
182194 const resolutionSelect = document . getElementById ( 'Resolution' ) as HTMLSelectElement ;
183195 const adfCheck = document . getElementById ( 'ADF' ) as HTMLInputElement ;
184- if ( ! this . dwtObject ) return ;
196+ if ( ! this . dwtObject || ! this . sourceList ) return ;
185197 this . dwtObject . IfShowUI = false ;
186198 await this . dwtObject . SelectDeviceAsync ( this . sourceList [ select . selectedIndex ] ) ;
187199 await this . dwtObject . OpenSourceAsync ( ) ;
0 commit comments