Skip to content

Commit e8ff8f5

Browse files
authored
Merge pull request #661 from ztyyLV/Jackson-branch
Jackson branch
2 parents dce39f0 + d022d9b commit e8ff8f5

File tree

2 files changed

+205
-2
lines changed

2 files changed

+205
-2
lines changed

getstarted/vue.md

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ permalink: /indepth/development/vue.html
1212

1313
[Vue](https://vuejs.org/) is a progressive framework for building user interfaces. Check out the following guide on how to integrate `DWT` into a Vue application.
1414

15+
<div class="multi-panel-switching-prefix"></div>
16+
17+
- [Vue](#vue)
18+
- [Vue 3](#vue3)
19+
20+
<div class="multi-panel-start"></div>
21+
1522
## Preparation
1623

1724
Make sure you have [node](https://nodejs.org/), [yarn](https://yarnpkg.com/cli/install), and [Vue CLI](https://cli.vuejs.org/) installed. `node 14.4.0` , `yarn 1.22.4`, and `@vue/cli 4.46` are used in the example below.
@@ -203,4 +210,200 @@ If you have installed `DWT` and have configured a valid `ProductKey` . You will
203210

204211
You should be able to open a file or capture an image.
205212

213+
<div class="multi-panel-end"></div>
214+
215+
<div class="multi-panel-start"></div>
216+
217+
## Preparation
218+
219+
The recommended version for Vue and Node is `v3.2.22` and `v16+` respectively.
220+
221+
## Create the sample project
222+
223+
### Create a bootstrapped raw Vue 3 application
224+
225+
Assume the project name is "dwt-vue3"
226+
227+
``` cmd
228+
npm init vue@latest
229+
```
230+
231+
### Navigate to the root directory of the application and install the `dwt` and `ncp` package
232+
233+
``` cmd
234+
cd dwt-vue3
235+
```
236+
237+
``` cmd
238+
npm install
239+
```
240+
241+
``` cmd
242+
npm install dwt
243+
```
244+
245+
``` cmd
246+
npm install ncp
247+
```
248+
249+
## Configure the project
250+
251+
Open `package.json` and change `scripts` as seen below:
252+
253+
``` json
254+
"scripts": {
255+
"dev": "ncp node_modules/dwt/dist public/dwt-resources && vite",
256+
"build": "ncp node_modules/dwt/dist public/dwt-resources && vite build",
257+
"preview": "vite preview"
258+
},
259+
```
260+
261+
> The change ensures the static files required to run `DWT` are copied over to the resulting built project.
262+
263+
## Start to implement
264+
265+
### Edit the default component
266+
267+
Create `localScan.vue` in the folder /src/components
268+
269+
```html
270+
<script setup>
271+
import Dynamsoft from "dwt";
272+
import { onMounted, onUnmounted, ref } from "vue";
273+
let selectedIndex = ref(0);
274+
let sourceList=ref([]);
275+
let DWObject;
276+
const containerId = "dwtcontrolContainer";
277+
onMounted(() => {
278+
/**
279+
* ResourcesPath & ProductKey must be set in order to use the library!
280+
*/
281+
Dynamsoft.DWT.AutoLoad = false;
282+
Dynamsoft.DWT.ResourcesPath = "/dwt-resources";
283+
Dynamsoft.DWT.ProductKey ="YOUR-PRODUCT-KEY";
284+
Dynamsoft.DWT.Containers = [
285+
{
286+
WebTwainId: "dwtObject",
287+
ContainerId: containerId,
288+
Width: "500px",
289+
Height: "600px",
290+
},
291+
];
292+
Dynamsoft.DWT.RegisterEvent("OnWebTwainReady", () => {
293+
Dynamsoft_OnReady();
294+
});
295+
Dynamsoft.DWT.Load();
296+
});
297+
onUnmounted(()=>{
298+
Dynamsoft.DWT.Unload();
299+
})
300+
function Dynamsoft_OnReady() {
301+
DWObject = Dynamsoft.DWT.GetWebTwain(containerId);
302+
DWObject.GetDevicesAsync()
303+
.then((deviceList) => {
304+
sourceList.value = deviceList;
305+
})
306+
.catch((e) => {
307+
console.error(e);
308+
});
309+
}
310+
/**
311+
* Acquire images from scanners
312+
*/
313+
function acquireImage() {
314+
DWObject.SelectDeviceAsync(sourceList.value[selectedIndex.value])
315+
.then(() => {
316+
return DWObject.AcquireImageAsync({IfCloseSourceAfterAcquire:true});
317+
})
318+
.catch((e) => {
319+
console.error(e);
320+
})
321+
}
322+
323+
/**
324+
* Open local images.
325+
*/
326+
function openImage() {
327+
DWObject.IfShowFileDialog = true;
328+
/**
329+
* Note:
330+
* This following line of code uses the PDF Rasterizer which is an extra add-on that is licensed seperately
331+
*/
332+
DWObject.Addon.PDF.SetConvertMode(Dynamsoft.DWT.EnumDWT_ConvertMode.CM_RENDERALL);
333+
DWObject.LoadImageEx(
334+
"",
335+
Dynamsoft.DWT.EnumDWT_ImageType.IT_ALL,
336+
() => {
337+
//success
338+
},
339+
() => {
340+
//failure
341+
}
342+
);
343+
}
344+
</script>
345+
346+
<template>
347+
<div>
348+
<select v-model="selectedIndex">
349+
<option
350+
v-for="(source, index) in sourceList"
351+
:value="index"
352+
:key="index"
353+
>
354+
{{ source.displayName }}
355+
</option>
356+
</select>
357+
<button @click="acquireImage()">Acquire Images</button>
358+
<button @click="openImage()">Open Documents</button>
359+
<div :id="containerId"></div>
360+
</div>
361+
</template>
362+
363+
<style scoped></style>
364+
```
365+
366+
> Note:
367+
> * `containerId` specifies the DIV to create `DWT` viewer, which is defined in the `template`.
368+
> * `OnWebTwainReady` is the callback triggered when `DWT` initialization succeeds.
369+
> * `ProductKey` must be set to a valid trial or full key.
370+
> * `ResourcesPath` is set to the location of the static files mentioned in [Configure the project](#configure-the-project).
371+
372+
Change the file /src/App.vue
373+
374+
```html
375+
<script setup>
376+
import HelloWorld from './components/localScan.vue'
377+
</script>
378+
379+
<template>
380+
<HelloWorld />
381+
</template>
382+
383+
<style scoped>
384+
</style>
385+
```
386+
387+
### Try running the project
388+
389+
``` cmd
390+
npm run dev
391+
```
392+
393+
#### On desktop
394+
395+
If you have installed `DWT` and have configured a valid `ProductKey` . You will have a working page to scan documents from your scanner now. Otherwise, you should see instructions on [this page]({{site.indepth}}features/initialize.html#installation-of-the-dynamsoft-service) that guides you on installing the library.
396+
397+
#### On mobile
398+
399+
For Android, the scanners that support ESCL can be used.
400+
401+
## Official Samples
402+
403+
Check out the following sample project:
404+
405+
* [dwt-vue](https://github.com/Dynamsoft/web-twain-vue-advanced)
406+
407+
<div class="multi-panel-end"></div>
206408

409+
<div class="multi-panel-switching-end"></div>

info/api/WebTwain_Acquire.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4623,7 +4623,7 @@ GetDevicesAsync(deviceType?: Dynamsoft.DWT.EnumDWT_DeviceType | number, refresh?
46234623

46244624
**Parameters**
46254625

4626-
`deviceType`: The device type. Please refere to [EnumDWT_DeviceType]({{site.info}}api/Dynamsoft_Enum.html#dynamsoftdwtenumdwt_borderstyle)
4626+
`deviceType`: The device type. Please refere to [EnumDWT_DeviceType]({{site.info}}api/Dynamsoft_Enum.html#dynamsoftdwtenumdwt_devicetype)
46274627

46284628
`refresh`: Default value is **false**
46294629

@@ -4778,4 +4778,4 @@ DWObject.GetDevicesAsync().then((deviceList)=>{
47784778
```
47794779

47804780

4781-
<div class="multi-panel-switching-end"></div>
4781+
<div class="multi-panel-switching-end"></div>

0 commit comments

Comments
 (0)