scan(options)

Use this function to start scanning a document.

Syntax 

1import { getDocumentScanner } from 'lightning/mobileCapabilities';
2getEvents(options: DocumentScannerOptions): Promise<Object>;

Parameters 

Returns 

A Promise object that resolves to an array containing one or more Document objects.

A rejected promise returns a DocumentScannerFailure.

Usage 

Use this function to scan a document and handle the results of the scan.

1myDocumentScanner
2.scan(options)
3.then((results) => {
4    // Do something with the result of the scan
5    this.scannedText = results.value;
6})
7.catch((error) => {
8    // Handle cancellation and scanning errors here
9    this.results = [];
10    console.error('Error code: ' + error.code); + 
11    console.error('Error message: ' + error.message);
12});
  • The design pattern of returning an array containing a single Document object instead of just the Document object is intentional. This flexibility makes it easier to add future enhancements without causing existing code to break.
  • If an error occurs, the error is returned via a rejected promise. Handle errors in a catch clause.
  • When the user cancels a scan, the promise is rejected with a DocumentScannerFailure.code value of USER_DISMISSED.

See Also

Release Preview

This release is in preview. Features described here don't become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can't guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.