react-native-scanbot-sdk
Version:
Scanbot Document and Barcode Scanner SDK React Native Plugin for Android and iOS
658 lines (645 loc) • 22.8 kB
text/typescript
import { NativeModules, Platform } from 'react-native';
import {
ApplyImageFiltersOnPageResult,
CreatePageResult,
DetectDocumentOnPageResult,
Page,
RotatePageResult,
SetDocumentImageResult,
} from './types';
import {
BarcodeScannerConfiguration,
BatchBarcodeScannerConfiguration,
CheckRecognizerConfiguration,
CroppingConfiguration,
DocumentScannerConfiguration,
FinderDocumentScannerConfiguration,
GenericDocumentRecognizerConfiguration,
HealthInsuranceCardScannerConfiguration,
LicensePlateScannerConfiguration,
MedicalCertificateRecognizerConfiguration,
MrzScannerConfiguration,
ScanbotSdkConfiguration,
TextDataScannerConfiguration,
VinScannerConfiguration,
} from './configurations';
import {
ApplyImageFiltersResult,
BarcodeScannerResult,
BatchBarcodeScannerResult,
CheckRecognizerResult,
CreatePDFResult,
CreateTIFFResult,
CroppingResult,
DetectBarcodesOnImageResult,
DetectDocumentResult,
DocumentExistsResult,
DocumentQualityAnalyzerResult,
DocumentScannerResult,
ExtractImagesFromPdfResult,
ExtractPagesFromPdfResult,
FinderDocumentScannerResult,
GenericDocumentRecognizerResult,
GetImageDataResult,
GetLicenseInfoResult,
GetOCRConfigsResult,
HealthInsuranceCardScannerResult,
InitializeSDKResult,
LicensePlateScannerResult,
MedicalCertificateScannerResult,
MrzScannerResult,
PerformOCRResult,
RecognizeEHICResult,
RecognizeGenericDocumentResult,
RecognizeMedicalCertificateResult,
RecognizeMRZResult,
RefreshImageUrisResult,
RotateImageResult,
StoredDocumentIDsResult,
TextDataScannerResult,
VinScannerResult,
WriteTIFFResult,
} from './results';
import {
CreatePDFArguments,
DetectBarcodesOnImageArguments,
DocumentQualityAnalyzerArguments,
ExtractImagesFromPdfArguments,
ExtractPagesFromPdfArguments,
PerformOCRArguments,
RecognizeGenericDocumentArguments,
RecognizeMedicalCertificateArguments,
WriteTIFFArguments,
} from './arguments';
import {
AddPageParams,
CreateDocumentParams,
DocumentFromLegacyPagesParams,
ModifyPageParams,
MovePageParams,
PDFFromDocumentParams,
RemovePageParams,
TIFFFromDocumentParams,
} from './parameters';
import { DocumentScannerMetadata, ResultWrapper, ResultWrapperWithMetadata } from './customTypes';
import { ParametricFilter } from './document/ParametricFilters';
import { CheckDocumentModelRootType } from './documents/CheckDocumentModel';
import { ScanbotBarcodeCameraView } from './components/barcode-camera-view/ScanbotBarcodeCameraView';
import { ScanbotDocumentScannerView } from './components/document-scanner-view/ScanbotDocumentScannerView';
import { DocumentData } from './document/DocumentData';
const LINKING_ERROR =
`The package 'react-native-scanbot-sdk' doesn't seem to be linked. Make sure: \n\n` +
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
'- You rebuilt the app after installing the package\n' +
'- You are not using Expo Go\n';
const ScanbotSDKImpl = NativeModules.RNScanbotSDK
? NativeModules.RNScanbotSDK
: new Proxy(
{},
{
get() {
throw new Error(LINKING_ERROR);
},
}
);
const ScanbotSDKUIImpl = NativeModules.RNScanbotRTUUI
? NativeModules.RNScanbotRTUUI
: new Proxy(
{},
{
get() {
throw new Error(LINKING_ERROR);
},
}
);
const ScanbotDocument = {
/**
* Create a new document.
*/
createDocument(params: CreateDocumentParams): Promise<ResultWrapper<DocumentData>> {
return ScanbotSDKImpl.createDocument(params);
},
/**
* Create a new document from legacy pages.
*/
createDocumentFromLegacyPages(
params: DocumentFromLegacyPagesParams
): Promise<ResultWrapper<DocumentData>> {
return ScanbotSDKImpl.createDocumentFromLegacyPages(params);
},
/**
* Create a new document from PDF file.
*/
createDocumentFromPDF(pdfUri: string): Promise<ResultWrapper<DocumentData>> {
return ScanbotSDKImpl.createDocumentFromPDF(pdfUri);
},
/**
* Check if a document with the given ID exists.
*/
documentExists(documentID: string): Promise<ResultWrapper<DocumentExistsResult>> {
return ScanbotSDKImpl.documentExists(documentID);
},
/**
* Load a document by its ID.
*/
loadDocument(documentID: string): Promise<ResultWrapper<DocumentData>> {
return ScanbotSDKImpl.loadDocument(documentID);
},
/**
* Gets all stored document IDs.
*/
storedDocumentIDs(): Promise<ResultWrapper<StoredDocumentIDsResult>> {
return ScanbotSDKImpl.storedDocumentIDs();
},
/**
* Clone a document by its ID.
*/
cloneDocument(documentID: string): Promise<ResultWrapper<DocumentData>> {
return ScanbotSDKImpl.cloneDocument(documentID);
},
/**
* Delete a document by its ID.
*/
deleteDocument(documentID: string): Promise<ResultWrapper<void>> {
return ScanbotSDKImpl.deleteDocument(documentID);
},
/**
* Delete all documents.
*/
deleteAllDocuments(): Promise<ResultWrapper<void>> {
return ScanbotSDKImpl.deleteAllDocuments();
},
/**
* Creates a PDF for the given document.
* Please check the extra options that are part of the input params to modify the created PDF file per your needs.
*/
createPDF(params: PDFFromDocumentParams): Promise<ResultWrapper<CreatePDFResult>> {
return ScanbotSDKImpl.createPDFForDocument(params);
},
/**
* Creates a TIFF for the given document.
* Please check the extra options that are part of the input params to modify the created TIFF file per your needs.
*/
createTIFF(params: TIFFFromDocumentParams): Promise<ResultWrapper<CreateTIFFResult>> {
return ScanbotSDKImpl.createTIFFForDocument(params);
},
/**
* Add a new page to a document and return the updated document.
*/
addPage(params: AddPageParams): Promise<ResultWrapper<DocumentData>> {
return ScanbotSDKImpl.addPage(params);
},
/**
* Move a page in a document and return the updated document.
*/
movePage(params: MovePageParams): Promise<ResultWrapper<DocumentData>> {
return ScanbotSDKImpl.movePage(params);
},
/**
* Modify a page in a document and return the updated document.
*/
modifyPage(params: ModifyPageParams): Promise<ResultWrapper<DocumentData>> {
return ScanbotSDKImpl.modifyPage(params);
},
/**
* Remove a page from a document.
*/
removePage(params: RemovePageParams): Promise<ResultWrapper<DocumentData>> {
return ScanbotSDKImpl.removePageFromDocument(params);
},
/**
* Remove all pages from a document in one batch operation.
*/
removeAllPages(documentID: string): Promise<ResultWrapper<DocumentData>> {
return ScanbotSDKImpl.removeAllPages(documentID);
},
};
const ScanbotSDKUI = {
/**
* Opens the Ready-To-Use UI Document Scanner screen with the desired configuration.
*
* @deprecated Use ***startDocumentScanner*** from ***'react-native-scanbot-sdk/ui_v2'*** instead.
*/
startDocumentScanner(
configuration: DocumentScannerConfiguration
): Promise<ResultWrapperWithMetadata<DocumentScannerResult, DocumentScannerMetadata>> {
return ScanbotSDKUIImpl.startDocumentScanner(configuration);
},
/**
* Forces the Ready-To-Use UI Document Scanner screen to close while it is running.
*
* @deprecated
*/
closeDocumentScanner(): Promise<void> {
return ScanbotSDKUIImpl.closeDocumentScanner();
},
/**
* Opens the Ready-To-Use UI Finder Document Scanner screen with the desired configuration.
*
* @deprecated Use ***startDocumentScanner*** from ***'react-native-scanbot-sdk/ui_v2'*** instead.
*/
startFinderDocumentScanner(
configuration: FinderDocumentScannerConfiguration
): Promise<ResultWrapper<FinderDocumentScannerResult>> {
return ScanbotSDKUIImpl.startFinderDocumentScanner(configuration);
},
/**
* Forces the Ready-To-Use UI Finder Document Scanner screen to close while it is running.
*
* @deprecated
*/
closeFinderDocumentScanner(): Promise<void> {
return ScanbotSDKUIImpl.closeFinderDocumentScanner();
},
/**
* Opens the Ready-To-Use UI Cropping screen with the desired configuration.
*
* @deprecated Use ***startCroppingScreen*** from ***'react-native-scanbot-sdk/ui_v2'*** instead.
*/
startCroppingScreen(
page: Page,
configuration: CroppingConfiguration
): Promise<ResultWrapper<CroppingResult>> {
return ScanbotSDKUIImpl.startCroppingScreen(page, configuration);
},
/**
* Forces the Ready-To-Use UI Cropping screen to close while it is running.
*
* @deprecated
*/
closeCroppingScreen(): Promise<void> {
return ScanbotSDKUIImpl.closeCroppingScreen();
},
/**
* Opens the Ready-To-Use UI MRZ Scanner screen with the desired configuration.
*/
startMrzScanner(
configuration: MrzScannerConfiguration
): Promise<ResultWrapper<MrzScannerResult>> {
return ScanbotSDKUIImpl.startMrzScanner(configuration);
},
/**
* Forces the Ready-To-Use UI MRZ Scanner screen to close while it is running.
*/
closeMrzScanner(): Promise<void> {
return ScanbotSDKUIImpl.closeMrzScanner();
},
/**
* Opens the Ready-To-Use UI Barcode Scanner screen with the desired configuration.
*
* @deprecated Use ***startBarcodeScanner*** from ***'react-native-scanbot-sdk/ui_v2'*** instead.
*/
startBarcodeScanner(
configuration: BarcodeScannerConfiguration
): Promise<ResultWrapper<BarcodeScannerResult>> {
return ScanbotSDKUIImpl.startBarcodeScanner(configuration);
},
/**
* Forces the Ready-To-Use UI Barcode Scanner screen to close while it is running.
*
* @deprecated
*/
closeBarcodeScanner(): Promise<void> {
return ScanbotSDKUIImpl.closeBarcodeScanner();
},
/**
* Opens the Ready-To-Use UI Batch Barcode Scanner screen with the desired configuration.
*
* @deprecated Use ***startBarcodeScanner*** from ***'react-native-scanbot-sdk/ui_v2'*** instead.
*/
startBatchBarcodeScanner(
configuration: BatchBarcodeScannerConfiguration
): Promise<ResultWrapper<BatchBarcodeScannerResult>> {
return ScanbotSDKUIImpl.startBatchBarcodeScanner(configuration);
},
/**
* Forces the Ready-To-Use UI Batch Barcode Scanner screen to close while it is running.
*
* @deprecated
*/
closeBatchBarcodeScanner(): Promise<void> {
return ScanbotSDKUIImpl.closeBatchBarcodeScanner();
},
/**
* Opens the Ready-To-Use UI European Health Insurance Card Scanner screen with the desired configuration.
*
* @deprecated Use ***startGenericDocumentRecognizer*** instead and enable ***DE_HEALTH_INSURANCE_CARD_FRONT*** and ***EU_HEALTH_INSURANCE_CARD*** document formats.
*/
startEHICScanner(
configuration: HealthInsuranceCardScannerConfiguration
): Promise<ResultWrapper<HealthInsuranceCardScannerResult>> {
return ScanbotSDKUIImpl.startEHICScanner(configuration);
},
/**
* Forces the Ready-To-Use UI European Health Insurance Card Scanner screen to close while it is running.
*
* @deprecated
*/
closeEHICScanner(): Promise<void> {
return ScanbotSDKUIImpl.closeEHICScanner();
},
/**
* Opens the Ready-To-Use UI Text Data Scanner screen with the desired configuration.
*/
startTextDataScanner(
configuration: TextDataScannerConfiguration
): Promise<ResultWrapper<TextDataScannerResult>> {
return ScanbotSDKUIImpl.startTextDataScanner(configuration);
},
/**
* Forces the Ready-To-Use UI Text Data Scanner screen to close while it is running.
*/
closeTextDataScanner(): Promise<void> {
return ScanbotSDKUIImpl.closeTextDataScanner();
},
/**
* Opens the Ready-To-Use UI License Plate Scanner screen with the desired configuration.
*/
startLicensePlateScanner(
configuration: LicensePlateScannerConfiguration
): Promise<ResultWrapper<LicensePlateScannerResult>> {
return ScanbotSDKUIImpl.startLicensePlateScanner(configuration);
},
/**
* Forces the Ready-To-Use UI License Plate Scanner screen to close while it is running.
*/
closeLicensePlateScanner(): Promise<void> {
return ScanbotSDKUIImpl.closeLicensePlateScanner();
},
/**
* Opens the Ready-To-Use UI Medical Certificate Recognizer screen with the desired configuration.
*/
startMedicalCertificateRecognizer(
configuration: MedicalCertificateRecognizerConfiguration
): Promise<ResultWrapper<MedicalCertificateScannerResult>> {
return ScanbotSDKUIImpl.startMedicalCertificateRecognizer(configuration);
},
/**
* Forces the Ready-To-Use UI Medical Certificate Recognizer screen to close while it is running.
*/
closeMedicalCertificateRecognizer(): Promise<void> {
return ScanbotSDKUIImpl.closeMedicalCertificateRecognizer();
},
/**
* Opens the Ready-To-Use UI Generic Document Recognizer screen with the desired configuration.
*/
startGenericDocumentRecognizer(
configuration: GenericDocumentRecognizerConfiguration
): Promise<ResultWrapper<GenericDocumentRecognizerResult>> {
return ScanbotSDKUIImpl.startGenericDocumentRecognizer(configuration);
},
/**
* Forces the Ready-To-Use UI Generic Document Recognizer screen to close while it is running.
*/
closeGenericDocumentRecognizer(): Promise<void> {
return ScanbotSDKUIImpl.closeGenericDocumentRecognizer();
},
/**
* Opens the Ready-To-Use UI Check Recognizer screen with the desired configuration.
*/
startCheckRecognizer(
configuration: CheckRecognizerConfiguration
): Promise<ResultWrapper<CheckRecognizerResult>> {
return ScanbotSDKUIImpl.startCheckRecognizer(configuration);
},
/**
* Forces the Ready-To-Use UI Check Recognizer screen to close while it is running.
*/
closeCheckRecognizer(): Promise<void> {
return ScanbotSDKUIImpl.closeCheckRecognizer();
},
/**
* Opens the Ready-To-Use UI VIN Scanner screen with the desired configuration.
*/
startVinScanner(
configuration: VinScannerConfiguration
): Promise<ResultWrapper<VinScannerResult>> {
return ScanbotSDKUIImpl.startVinScanner(configuration);
},
/**
* Forces the Ready-To-Use UI VIN Scanner screen to close while it is running.
*/
closeVinScanner(): Promise<void> {
return ScanbotSDKUIImpl.closeVinScanner();
},
};
const ScanbotSDK = {
UI: ScanbotSDKUI,
Document: ScanbotDocument,
/**
* Initializes the Scanbot SDK with the preferred configuration.
*/
initializeSDK(config: ScanbotSdkConfiguration): Promise<ResultWrapper<InitializeSDKResult>> {
return ScanbotSDKImpl.initializeSDK(config);
},
/**
* Provides complete information about the current license status.
*/
getLicenseInfo(): Promise<ResultWrapper<GetLicenseInfoResult>> {
return ScanbotSDKImpl.getLicenseInfo();
},
/**
* Returns the available OCR configs.
*/
getOCRConfigs(): Promise<ResultWrapper<GetOCRConfigsResult>> {
return ScanbotSDKImpl.getOCRConfigs();
},
/**
* Removes all files generated by this plugin.
*/
cleanup(): Promise<ResultWrapper<void>> {
return ScanbotSDKImpl.cleanup();
},
/**
* Recreates the given pages to refresh the Image URIs.
*/
refreshImageUris(args: { pages: Page[] }): Promise<ResultWrapper<RefreshImageUrisResult>> {
return ScanbotSDKImpl.refreshImageUris(args);
},
/**
* Detects barcodes on the image represented by the file URI. The image file URI is part of the input arguments.
*/
detectBarcodesOnImage(
args: DetectBarcodesOnImageArguments
): Promise<ResultWrapper<DetectBarcodesOnImageResult>> {
return ScanbotSDKImpl.detectBarcodesOnImage(args);
},
/**
* Applies the given filters to the given image, and returns its URI.
*/
applyImageFilters(
imageFileUri: string,
filters: ParametricFilter[]
): Promise<ResultWrapper<ApplyImageFiltersResult>> {
return ScanbotSDKImpl.applyImageFilters(imageFileUri, filters);
},
/**
* Applies the given filters to the given page.
*/
applyImageFiltersOnPage(
page: Page,
filters: ParametricFilter[]
): Promise<ResultWrapper<ApplyImageFiltersOnPageResult>> {
return ScanbotSDKImpl.applyImageFiltersOnPage(page, filters);
},
/**
* Creates a page with the image located at the given URI.
*/
createPage(imageUri: string): Promise<ResultWrapper<CreatePageResult>> {
return ScanbotSDKImpl.createPage(imageUri);
},
/**
* Removes the given page from the storage.
*/
removePage(page: Page): Promise<ResultWrapper<void>> {
return ScanbotSDKImpl.removePage(page);
},
/**
* Rotates the given page for the number of 90 degree counterclockwise rotations. Negative values will rotate clockwise.
*/
rotatePage(page: Page, times: number): Promise<ResultWrapper<RotatePageResult>> {
return ScanbotSDKImpl.rotatePage(page, times);
},
/**
* Applies the given image to the desired page.
*/
setDocumentImage(page: Page, imageUri: string): Promise<ResultWrapper<SetDocumentImageResult>> {
return ScanbotSDKImpl.setDocumentImage(page, imageUri);
},
/**
* Detects document on the given image and returns the result.
*/
detectDocument(imageFileUri: string): Promise<ResultWrapper<DetectDocumentResult>> {
return ScanbotSDKImpl.detectDocument(imageFileUri);
},
/**
* Detects document on the given page and returns the result.
*/
detectDocumentOnPage(page: Page): Promise<ResultWrapper<DetectDocumentOnPageResult>> {
return ScanbotSDKImpl.detectDocumentOnPage(page);
},
/**
* Extracts images from a PDF represented by the file URL. The PDF file URL is part of the input arguments.
*/
extractImagesFromPdf(
args: ExtractImagesFromPdfArguments
): Promise<ResultWrapper<ExtractImagesFromPdfResult>> {
return ScanbotSDKImpl.extractImagesFromPdf(args);
},
/**
* Extracts images from a PDF represented by the file URL, creates pages from them and returns the created pages.
* The PDF file URL is part of the input arguments.
*/
extractPagesFromPdf(
args: ExtractPagesFromPdfArguments
): Promise<ResultWrapper<ExtractPagesFromPdfResult>> {
return ScanbotSDKImpl.extractPagesFromPdf(args);
},
/**
* Returns the BASE64 Image Data for the given image.
*/
getImageData(imageFileUri: string): Promise<ResultWrapper<GetImageDataResult>> {
return ScanbotSDKImpl.getImageData(imageFileUri);
},
/**
* Rotates the given image by the specified degrees counterclockwise. Negative values will rotate clockwise.
*/
rotateImage(imageFileUri: string, degrees: number): Promise<ResultWrapper<RotateImageResult>> {
return ScanbotSDKImpl.rotateImage(imageFileUri, degrees);
},
/**
* Detects the quality of the document on a still image.
*/
documentQualityAnalyzer(
args: DocumentQualityAnalyzerArguments
): Promise<ResultWrapper<DocumentQualityAnalyzerResult>> {
return ScanbotSDKImpl.documentQualityAnalyzer(args);
},
/**
* Recognizes a Check on the given image.
* Set desired check standards or leave it empty/undefined to recognize all supported checks.
*/
recognizeCheck(args: {
imageFileUri: string;
acceptedCheckStandards?: CheckDocumentModelRootType[];
}): Promise<ResultWrapper<CheckRecognizerResult>> {
return ScanbotSDKImpl.recognizeCheck(args);
},
/**
* Recognizes an MRZ on the given image.
*/
recognizeMrz(imageFileUri: string): Promise<ResultWrapper<RecognizeMRZResult>> {
return ScanbotSDKImpl.recognizeMrz(imageFileUri);
},
/**
* Recognizes a Medical Certificate on the given image.
* Modify the result with extra options that are part of the input arguments.
*/
recognizeMedicalCertificate(
args: RecognizeMedicalCertificateArguments
): Promise<ResultWrapper<RecognizeMedicalCertificateResult>> {
return ScanbotSDKImpl.recognizeMedicalCertificate(args);
},
/**
* Recognizes a European Health Insurance Card (EHIC) on the given image.
*
* @deprecated Use ***recognizeGenericDocument*** instead and enable ***DE_HEALTH_INSURANCE_CARD_FRONT*** and ***EU_HEALTH_INSURANCE_CARD*** document formats.
*/
recognizeEHIC(imageFileUri: string): Promise<ResultWrapper<RecognizeEHICResult>> {
return ScanbotSDKImpl.recognizeEHIC(imageFileUri);
},
/**
* Recognizes a generic document on the given image.
* Set the expected generic document formats or leave it empty/undefined to recognize all supported generic document formats.
*/
recognizeGenericDocument(
args: RecognizeGenericDocumentArguments
): Promise<ResultWrapper<RecognizeGenericDocumentResult>> {
return ScanbotSDKImpl.recognizeGenericDocument(args);
},
/**
* Performs OCR on given images. Set preferred ***ocrConfiguration*** engine, or leave it undefined to use the default one which is ***OCRScanbotEngineConfiguration***.
* If ***OCRTesseractConfiguration*** is used, the expected ***languages*** need to be set.
*/
performOCR(args: PerformOCRArguments): Promise<ResultWrapper<PerformOCRResult>> {
return ScanbotSDKImpl.performOCR(args);
},
/**
* Creates a PDF using the given list of image file URIs.
* Please check the extra options that are part of the input arguments to modify the created PDF file per your needs.
*/
createPDF(args: CreatePDFArguments): Promise<ResultWrapper<CreatePDFResult>> {
return ScanbotSDKImpl.createPDF(args);
},
/**
* Creates a TIFF using the given list of image file URIs.
* Please check the extra options that are part of the input arguments to modify the created TIFF file per your needs.
*/
writeTIFF(args: WriteTIFFArguments): Promise<ResultWrapper<WriteTIFFResult>> {
return ScanbotSDKImpl.writeTIFF(args);
},
};
export default ScanbotSDK;
export type ScanbotSDKUI = typeof ScanbotSDKUI;
export type ScanbotDocument = typeof ScanbotDocument;
export * from './arguments';
export * from './parameters';
export * from './configurations';
export * from './customTypes';
export * from './results';
export * from './types';
export { Point } from './utils';
export * from './components/barcode-camera-view/ScanbotBarcodeCameraViewProperties';
export * from './components/document-scanner-view/ScanbotDocumentScannerViewProperties';
export { ScanbotBarcodeCameraView, ScanbotDocumentScannerView };
export * from './documents/BarcodeDocumentModel';
export * from './documents/CheckDocumentModel';
export * from './documents/CommonFieldType';
export * from './documents/DocumentsModel';
export * from './documents/GenericDocument';
export * from './document/DocumentData';
export * from './document/DocumentDetectionStatus';
export * from './document/DocumentQuality';
export * from './document/PageData';
export * from './document/PageImageSource';
export * from './document/ParametricFilters';