We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All
ReferencesAIVision KitArkTS ComponentsDocumentScanner (Document Scanning Control)

DocumentScanner (Document Scanning Control)

Phone5.0.0(12)+Tablet5.0.0(12)+

The document scanning control provides the service of taking photos of documents and converting them into high-definition scanned copies. Users can capture document photos with their phones, and these photos can be automatically cropped, optimized, and then saved or shared as JPEG images or PDF files. Users can also use this service to identify tables from photos just taken or those in the gallery and generate table documents.

Since: 5.0.0(12)

Modules to Import

Collapse
Word wrap
Dark theme
Copy code
  1. import { DocType, DocumentScanner, DocumentScannerConfig, SaveOption, FilterId, ShootingMode, EditTab, DocumentScannerResultCallback, DocumentScannerController } from '@kit.VisionKit';

DocumentScanner

Phone5.0.0(12)+Tablet5.0.0(12)+

Document scanning control, which can be integrated to implement document scanning.

Atomic service API: This API can be used in atomic services since version 5.0.0(12).

Decorator type: @Component

System capability: SystemCapability.AI.Component.DocScan

Model restriction: This API can be used only in the stage model.

Since: 5.0.0(12)

Parameters:

Expand
Name Type Mandatory Decorator Type Description
scannerConfig DocumentScannerConfig Yes - Document scanning capability configuration.
onResult DocumentScannerResultCallback Yes - Callback of the document scanning result.

build

Phone5.0.0(12)+Tablet5.0.0(12)+

build(): void

Constructs a DocumentScanner object. You do not need to call this method.

Atomic service API: This API can be used in atomic services since version 5.0.0(12).

System capability: SystemCapability.AI.Component.DocScan

Model restriction: This API can be used only in the stage model.

Since: 5.0.0(12)

DocumentScannerConfig

Phone5.0.0(12)+Tablet5.0.0(12)+

Document scanning capability configuration.

Atomic service API: This API can be used in atomic services since version 5.0.0(12).

System capability: SystemCapability.AI.Component.DocScan

Model restriction: This API can be used only in the stage model.

Since: 5.0.0(12)

Expand
Name Type Read-Only Optional Description
maxShotCount number No Yes

Maximum number of document photos captured each time. The default value is 1. The maximum value is 50.

The value is an integer ranging from 1 to 50.

supportType DocType[] No No

Supported file types. The default value is [DocType.DOC].

Device behavior differences: Some device models do not support [DocType.SHEET]. You can use isSheetDetectionSupported to check whether the current device supports the table extraction function. If an unsupported value is set for a device model, the default value will be used.

isGallerySupported boolean No Yes Indicates whether images can be selected from the gallery. true: yes false: no The default value is true.
defaultFilterId FilterId No Yes Initial filter effect. By default, the enhanced filter is used.
editTabs EditTab[] No Yes Buttons displayed in the tab bar. By default, all buttons are displayed.
defaultShootingMode ShootingMode No Yes Initial shooting mode. By default, manual shooting is used.
isShareable boolean No Yes Whether the sharing function is supported. true: yes false: no By default, this function is supported.
saveOptions SaveOption[] No Yes Saving options. When supportType is set to [DOC], the default value is [SaveOption.JPG]. When supportType is set to [SHEET], the default value is [SaveOption.EXCEL]. When supportType is set to [DOC,SHEET], the default value is [SaveOption.JPG, SaveOption.EXCEL]. The saving options for the DOC and SHEET types are independent of each other.
originalUris string[] No Yes

Initially provided image URI list. If the value is not empty, it is directly used to jump to the editing screen. The value is left empty by default. The maximum length of the array is 50. Images that do not meet the following specifications (unit: px) will be removed:

1. The minimum length of a single side is 224, and the maximum length is 8000.

2. The product of the image width and height is less than or equal to 6000 x 8000.

3. The ratio of the image height to its width and the ratio of the image width to its height are less than or equal to 3.

NOTE

This parameter became functional in version 5.0.5(17) and was a reserved parameter in earlier versions.

DocType

Phone5.0.0(12)+Tablet5.0.0(12)+

Enumeration of supported file types.

Atomic service API: This API can be used in atomic services since version 5.0.0(12).

System capability: SystemCapability.AI.Component.DocScan

Model restriction: This API can be used only in the stage model.

Since: 5.0.0(12)

Expand
Name Value Description
DOC 0 Document type.
SHEET 1 Sheet type.

FilterId

Phone5.0.0(12)+Tablet5.0.0(12)+

Enumeration of filters added to images.

Atomic service API: This API can be used in atomic services since version 5.0.0(12).

System capability: SystemCapability.AI.Component.DocScan

Model restriction: This API can be used only in the stage model.

Since: 5.0.0(12)

Expand
Name Value Description
ORIGINAL 0 Original image filter.
MONOCHROME 1 Black and white filter.
STRENGTHEN 2 Enhanced filter.

ShootingMode

Phone5.0.0(12)+Tablet5.0.0(12)+

Enumeration of photo shooting modes.

Atomic service API: This API can be used in atomic services since version 5.0.0(12).

System capability: SystemCapability.AI.Component.DocScan

Model restriction: This API can be used only in the stage model.

Since: 5.0.0(12)

Expand
Name Value Description
AUTO 0 Automatic shooting mode.
MANUAL 1 Manual shooting mode.

EditTab

Phone5.0.0(12)+Tablet5.0.0(12)+

Enumeration of buttons in the tab bar.

Atomic service API: This API can be used in atomic services since version 5.0.0(12).

System capability: SystemCapability.AI.Component.DocScan

Model restriction: This API can be used only in the stage model.

Since: 5.0.0(12)

Expand
Name Value Description
ROTATE_TAB 0 Rotate button.
DELETE_TAB 1 Delete button.
RESHOOT_TAB 2 Reshoot button.

SaveOption

Phone5.0.0(12)+Tablet5.0.0(12)+

Enumeration of saving options.

Atomic service API: This API can be used in atomic services since version 5.0.0(12).

System capability: SystemCapability.AI.Component.DocScan

Model restriction: This API can be used only in the stage model.

Since: 5.0.0(12)

Expand
Name Value Description
JPG 0 JPEG (only for saving documents).
PDF 1 PDF (only for saving documents).
EXCEL 2 Excel (only for saving sheets).

DocumentScannerResultCallback

Phone5.0.0(12)+Tablet5.0.0(12)+

type DocumentScannerResultCallback = (code: number, saveType: SaveOption, uris: string[]) => void

Callback of the document scanning result.

Atomic service API: This API can be used in atomic services since version 5.0.0(12).

System capability: SystemCapability.AI.Component.DocScan

Model restriction: This API can be used only in the stage model.

Since: 5.0.0(12)

Parameters:

Expand
Parameter Type Mandatory Description
code number Yes

Result code.

-1: No result is returned.

200: The recognition is successful.

1008601001: invalid URIs.

NOTE

The result code 1008601001 is supported since 5.0.5 (17).

saveType SaveOption Yes Format in which the result is saved.
uris string[] Yes Document URI list.

DocumentScannerController

Phone26.0.0+Tablet26.0.0+

Document scanner controller, which is used to control interactions.

Atomic service API: This API can be used in atomic services since version 26.0.0.

System capability: SystemCapability.AI.Component.DocScan

Model restriction: This API can be used only in the stage model.

Since: 26.0.0

isSheetDetectionSupported

Phone26.0.0+Tablet26.0.0+

isSheetDetectionSupported(): boolean

Checks whether the device supports table extraction.

Atomic service API: This API can be used in atomic services since version 26.0.0.

System capability: SystemCapability.AI.Component.DocScan

Model restriction: This API can be used only in the stage model.

Since: 26.0.0

Returns

Expand
Type Description
boolean If the current device supports this function, true is returned. Otherwise, false is returned.

Example

Collapse
Word wrap
Dark theme
Copy code
  1. import { DocumentScannerController } from '@kit.VisionKit';
  2. let documentScannerController: DocumentScannerController = new DocumentScannerController();
  3. let isSheetSupported = documentScannerController.isSheetDetectionSupported();
  4. console.info(`isSheetSupported: ${isSheetSupported}`);