From 49e81cc4147c42ba1dd140b4e8cb639e3bb084f1 Mon Sep 17 00:00:00 2001 From: Robert Coie Date: Sun, 2 Jun 2019 21:55:40 -0700 Subject: [PATCH] feat(document-scanner): add plugin (#3043) --- .../plugins/document-scanner/index.ts | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 src/@ionic-native/plugins/document-scanner/index.ts diff --git a/src/@ionic-native/plugins/document-scanner/index.ts b/src/@ionic-native/plugins/document-scanner/index.ts new file mode 100644 index 000000000..fe6279ca7 --- /dev/null +++ b/src/@ionic-native/plugins/document-scanner/index.ts @@ -0,0 +1,79 @@ +import { Injectable } from '@angular/core'; +import { Cordova, IonicNativePlugin, Plugin } from '@ionic-native/core'; + +export enum DocumentScannerSourceType { + /** + * Scan directly from device camera. + * This is the default. + */ + CAMERA = 1, + + /** + * Scan from an image already stored on device. + */ + GALLERY = 0 +} + +export interface DocumentScannerOptions { + /** + * Choose to scan from camera or existing image file. Only valid for Android. + */ + sourceType?: DocumentScannerSourceType; + + /** + * Filename to save scanned image to (minus extension, which is always ".png"). + * Only valid for iOS. Caller is responsible for cleaning up any files created + * if this parameter is set to anything other than the default value, + * which is "image". + */ + fileName?: string; +} + +/** + * @name Document Scanner + * @description + * This plugin processes images of documents, compensating for perspective. + * + * @usage + * ```typescript + * import { DocumentScanner, DocumentScannerOptions } from '@ionic-native/document-scanner'; + * + * + * constructor(private documentScanner: DocumentScanner) { } + * + * ... + * + * let opts: DocumentScannerOptions = {}; + * this.documentScanner.scanDocument(opts) + * .then((res: string) => console.log(res)) + * .catch((error: any) => console.error(error)); + * + * ``` + * + * @interfaces + * DocumentScannerOptions + * @enums + * DocumentScannerSourceType + */ +@Plugin({ + pluginName: 'DocumentScanner', + plugin: 'cordova-plugin-document-scanner', + pluginRef: 'scan', + repo: 'https://github.com/NeutrinosPlatform/cordova-plugin-document-scanner', + platforms: ['Android', 'iOS'] +}) +@Injectable() +export class DocumentScanner extends IonicNativePlugin { + + /** + * Scan a document + * @param opts {DocumentScannerOptions} optional parameter for controlling scanning + * @return {Promise} file URL of scanned document image + */ + @Cordova({ + callbackOrder: 'reverse' + }) + scanDoc(opts?: DocumentScannerOptions): Promise { + return; + } +}