@@ -46,10 +46,13 @@ In this example, we will scan VIZ documents, so we also need to set [IdCaptureLo
4646import { DataCaptureContext } from " @scandit/web-datacapture-core" ;
4747import { idCaptureLoader } from " @scandit/web-datacapture-id" ;
4848
49- const context = await DataCaptureContext .forLicenseKey (" -- ENTER YOUR SCANDIT LICENSE KEY HERE --" , {
50- libraryLocation: " /self-hosted-sdc-lib/" ,
51- moduleLoaders: [idCaptureLoader ({ enableVIZDocuments: true })],
52- });
49+ const context = await DataCaptureContext .forLicenseKey (
50+ " -- ENTER YOUR SCANDIT LICENSE KEY HERE --" ,
51+ {
52+ libraryLocation: " /self-hosted-sdc-lib/" ,
53+ moduleLoaders: [idCaptureLoader ({ enableVIZDocuments: true })],
54+ }
55+ );
5356```
5457
5558::: tip
@@ -88,7 +91,7 @@ await view.setContext(context);
8891
8992## Add the Camera
9093
91- You need to also create the [ Camera] ( https://docs.scandit.com/data-capture-sdk/web/core/api/camera.html#class-scandit.datacapture.core.Camera ' Camera class ' ) :
94+ You need to also create the [ Camera] ( https://docs.scandit.com/data-capture-sdk/web/core/api/camera.html#class-scandit.datacapture.core.Camera " Camera class " ) :
9295
9396``` ts
9497import { Camera } from " @scandit/web-datacapture-core" ;
@@ -113,14 +116,14 @@ By default, [anonymized data](./advanced.md#configure-data-anonymization) is not
113116
114117``` ts
115118import {
116- IdCapture ,
117- IdCaptureSettings ,
118- IdCard ,
119- Region ,
120- RegionSpecific ,
121- Passport ,
122- SingleSideScanner ,
123- FullDocumentScanner
119+ IdCapture ,
120+ IdCaptureSettings ,
121+ IdCard ,
122+ Region ,
123+ RegionSpecific ,
124+ Passport ,
125+ SingleSideScanner ,
126+ FullDocumentScanner ,
124127} from " @scandit/web-datacapture-id" ;
125128
126129const settings = new IdCaptureSettings ();
@@ -138,10 +141,14 @@ settings.rejectedDocuments.push(new Passport(Region.Cuba));
138141// To scan only one-sided documents and a given zone:
139142// Signature: SingleSideScanner(barcode: boolean, machineReadableZone boolean, visualInspectionZone: boolean)
140143// This would only scan a single side document having an MRZ:
141- settings .scanner = new IdCaptureScanner ({ physicalDocument: new SingleSideScanner (true , false , false ) });
144+ settings .scanner = new IdCaptureScanner ({
145+ physicalDocument: new SingleSideScanner (true , false , false ),
146+ });
142147
143148// To scan both sides of the document:
144- settings .scanner = new IdCaptureScanner ({ physicalDocument: new FullDocumentScanner () });
149+ settings .scanner = new IdCaptureScanner ({
150+ physicalDocument: new FullDocumentScanner (),
151+ });
145152```
146153
147154Create a new ID Capture mode with the chosen settings:
@@ -158,12 +165,12 @@ To receive scan results, implement [IdCaptureListener](https://docs.scandit.com/
158165import { type CapturedId , RejectionReason } from " @scandit/web-datacapture-id" ;
159166
160167idCapture .addListener ({
161- didCaptureId : (capturedId : CapturedId ) => {
162- // Success! Handle extracted data here.
163- },
164- didRejectId : (capturedId : CapturedId , reason : RejectionReason ) => {
165- // Something went wrong. Inspect the reason to determine the follow-up action.
166- }
168+ didCaptureId : (capturedId : CapturedId ) => {
169+ // Success! Handle extracted data here.
170+ },
171+ didRejectId : (capturedId : CapturedId , reason : RejectionReason ) => {
172+ // Something went wrong. Inspect the reason to determine the follow-up action.
173+ },
167174});
168175```
169176
@@ -181,17 +188,17 @@ On a successful scan you may read the extracted data from `capturedId`:
181188
182189``` ts
183190didCaptureId : async (capturedId : CapturedId ) => {
184- // stop processing new frames, we have a result
185- await idCapture .setEnabled (false );
191+ // stop processing new frames, we have a result
192+ await idCapture .setEnabled (false );
186193
187- const fullName = capturedId .fullName ;
188- const dateOfBirth = capturedId .dateOfBirth ;
189- const dateOfExpiry = capturedId .dateOfExpiry ;
190- const documentNumber = capturedId .documentNumber ;
194+ const fullName = capturedId .fullName ;
195+ const dateOfBirth = capturedId .dateOfBirth ;
196+ const dateOfExpiry = capturedId .dateOfExpiry ;
197+ const documentNumber = capturedId .documentNumber ;
191198
192- // Process data:
193- processData (fullName , dateOfBirth , dateOfExpiry , documentNumber );
194- }
199+ // Process data:
200+ processData (fullName , dateOfBirth , dateOfExpiry , documentNumber );
201+ };
195202```
196203
197204::: tip
@@ -225,10 +232,7 @@ The overlay informs and guides the user during the scanning process. Create an i
225232``` ts
226233import { IdCaptureOverlay } from " @scandit/web-datacapture-id" ;
227234
228- const overlay = await IdCaptureOverlay .withIdCaptureForView (
229- idCapture ,
230- view
231- );
235+ const overlay = await IdCaptureOverlay .withIdCaptureForView (idCapture , view );
232236```
233237
234238The overlay chooses the displayed UI automatically, based on the selected [ IdCaptureSettings] ( https://docs.scandit.com/data-capture-sdk/web/id-capture/api/id-capture-settings.html#class-scandit.datacapture.id.IdCaptureSettings ) .
@@ -248,3 +252,92 @@ await camera.switchToDesiredState(FrameSourceState.On);
248252```
249253
250254You can also enable or disable IdCapture by using [ setEnabled] ( https://docs.scandit.com/data-capture-sdk/web/id-capture/api/id-capture.html#method-scandit.datacapture.id.IdCapture.SetEnabled ) whenever you need to.
255+
256+ ## Complete IdCapture Example
257+
258+ ``` js
259+ import {
260+ Camera ,
261+ DataCaptureContext ,
262+ DataCaptureView ,
263+ FrameSourceState ,
264+ } from " @scandit/web-datacapture-core" ;
265+ import {
266+ IdCapture ,
267+ IdCaptureOverlay ,
268+ IdCaptureSettings ,
269+ IdCard ,
270+ Passport ,
271+ Region ,
272+ FullDocumentScanner ,
273+ IdCaptureScanner ,
274+ RejectionReason ,
275+ idCaptureLoader ,
276+ } from " @scandit/web-datacapture-id" ;
277+
278+ const context = await DataCaptureContext .forLicenseKey (
279+ " -- ENTER YOUR SCANDIT LICENSE KEY HERE --" ,
280+ {
281+ libraryLocation:
282+ " https://cdn.jsdelivr.net/npm/@scandit/web-datacapture-id@8/sdc-lib/" ,
283+ moduleLoaders: [idCaptureLoader ({ enableVIZDocuments: true })],
284+ }
285+ );
286+
287+ const view = await DataCaptureView .forContext (context);
288+ view .connectToElement (document .body );
289+
290+ const camera = Camera .pickBestGuess ();
291+ await camera .applySettings (IdCapture .recommendedCameraSettings );
292+ await context .setFrameSource (camera);
293+
294+ const settings = new IdCaptureSettings ();
295+ settings .acceptedDocuments .push (new IdCard (Region .Any ));
296+ settings .acceptedDocuments .push (new Passport (Region .Any ));
297+ settings .scanner = new IdCaptureScanner ({
298+ physicalDocument: new FullDocumentScanner (),
299+ });
300+
301+ const idCapture = await IdCapture .forContext (context, settings);
302+
303+ idCapture .addListener ({
304+ didCaptureId: async (capturedId ) => {
305+ await idCapture .setEnabled (false );
306+
307+ console .log (" Captured ID:" , {
308+ fullName: capturedId .fullName ,
309+ dateOfBirth: capturedId .dateOfBirth ,
310+ documentNumber: capturedId .documentNumber ,
311+ dateOfExpiry: capturedId .dateOfExpiry ,
312+ });
313+ },
314+ didRejectId : (capturedId , reason ) => {
315+ console .log (" ID rejected:" , reason);
316+
317+ if (reason === RejectionReason .Timeout ) {
318+ console .log (" Scan timed out. Please try again." );
319+ } else if (reason === RejectionReason .NotAcceptedDocumentType ) {
320+ console .log (" Document type not accepted." );
321+ }
322+ },
323+ });
324+
325+ const overlay = await IdCaptureOverlay .withIdCaptureForView (idCapture, view);
326+
327+ async function mount () {
328+ await camera .switchToDesiredState (FrameSourceState .On );
329+ await idCapture .setEnabled (true );
330+ }
331+
332+ async function unmount () {
333+ await camera .switchToDesiredState (FrameSourceState .Off );
334+ await idCapture .setEnabled (false );
335+ }
336+
337+ mount ().catch (async (error ) => {
338+ console .error (error);
339+ await unmount ();
340+ });
341+ ```
342+
343+ A more complete example can be found [ here on StackBlitz] ( https://stackblitz.com/github/Scandit/datacapture-web-samples/tree/master/02_ID_Scanning_Samples/IdCaptureSimpleSample ) .
0 commit comments