0.0.5 • Published 2 months ago

@dani.dev.pm/cordova-plugin-mlkit-doc-scanner v0.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

Cordova Plugin: ML Kit Document Scanner

An Android plugin that implements Google's ML Kit Document Scanner in a Cordova/Ionic app.

Check here the documentation for MLKit document scanner.

Installation

To install the plugin in Ionic:

ionic cordova plugin add @dani.dev.pm/cordova-plugin-mlkit-doc-scanner

Usage

import MLKitDocScanner from '@dani.dev.pm/cordova-plugin-mlkit-doc-scanner';
MLKitDocScanner.scanDocument(options)
.then((result) => {
// Handle the scan result
})
.catch((error) => {
// Handle any errors
});

// OR

const result: ScanResult = await MLKitDocScanner.scanDocument(options);

API Reference

MLKitDocScanner

The main interface for the ML Kit Document Scanner.

Methods

scanDocument(options: ScanOptions): Promise<ScanResult>

Scans a document with the given options.

  • options: Options for scanning the document (see ScanOptions interface).
  • Returns: A promise that resolves to the scan result (see ScanResult interface).

Interfaces

ScanOptions

Options for scanning documents.

PropertyTypeDescriptionDefault
pageLimit?numberThe maximum number of pages to scan.No limit
includeJpeg?booleanWhether to include JPEG images in the scan result.true
includePdf?booleanWhether to include a PDF in the scan result.true

ScanError

Interface representing an error that occurred during document scanning.

PropertyTypeDescription
codeScanErrorCodeThe error code.
messagestringThe error message.

ScanResult

Result of a document scan.

PropertyTypeDescription
images?string[]Array of image URIs if JPEG format is included.
pdf?stringURI of the PDF if PDF format is included.

Error Codes

The following error codes are defined in the ScanErrorCode enum:

Error CodeDescription
SCANNING_RESULT_NULLThe scanning result is null.
NO_PAGES_SCANNEDNo pages were scanned.
JSON_PROCESSING_ERRORAn error occurred while processing JSON data.
SCANNER_START_FAILEDThe scanner failed to start.
SCANNING_CANCELLEDThe scanning process was cancelled by the user.
SCANNING_FAILEDThe scanning process failed for an unknown reason.

Example

import MLKitDocScanner from '@dani.dev.pm/cordova-plugin-mlkit-doc-scanner';
const scanOptions: ScanOptions = {
    pageLimit: 5,
    includeJpeg: true,
    includePdf: true
};

try {
    const { images, pdf } = await MLKitDocScanner.scanDocument(scanOptions);
    console.log('Scanned jpeg of each page URIs:', images);
    console.log('Scanned PDF uri:', pdf);
} catch (error) {
    const scanError = error as ScanError;
    switch (scanError.code) {
        case ScanErrorCode.SCANNING_CANCELLED:
            console.log('User cancelled the scanning process');
            break;
        case ScanErrorCode.NO_PAGES_SCANNED:
            console.log('No pages were scanned');
            break;
    }
}
0.0.5

2 months ago

0.0.4

2 months ago

0.0.3

2 months ago

0.0.2

2 months ago

0.0.1

2 months ago