@docutain/cordova-plugin-docutain-sdk
Version:
Cordova plugin of the Docutain Document Scanner SDK for Android and iOS. High quality document scanning, data extraction, text recognition and PDF creation for your apps. Easily scan documents in your app.
166 lines (162 loc) • 5.78 kB
JavaScript
/**
* Docutain SDK Cordova Plugin
* Copyright (c) 2024 INFOSOFT Informations- und Dokumentationssysteme GmbH. All rights reserved.
*
* Docutain SDK Cordova Plugin is a commercial product and requires a license.
* Details found in the LICENSE file in the root directory of this source tree.
*/
function execDocutain(actionName, options) {
var result = new Promise(function (resolve, reject) {
try {
cordova.exec(resolve, reject, "DocutainSDKCordova", actionName, (options ? options : []));
}
catch (err) {
console.log("execDocutain exception: " + JSON.stringify(err));
reject(JSON.stringify(err));
}
});
return result;
}
module.exports = {
/**
* Initializes the Docutain SDK.
* This method needs to be called prior to using any functionality of the Docutain SDK.
* @param licenseKey your Docutain SDK license key.
*/
initSDK: function (licenseKey) {
return execDocutain('initSDK', [licenseKey]);
},
/**
* Starts the document scanner.
* @param config an instance of DocumentScannerConfiguration.
*/
scanDocument: function (config) {
return execDocutain('scanDocument', [config]);
},
/**
* This method loads image or PDF file as document or document page.
*
* @param fileUri the file uri where to save the PDF document.
*/
loadFile: function (fileUri) {
return execDocutain('loadFile', [fileUri]);
},
/**
* Detects the text of the currently loaded document and returns it.
*/
getText: function () {
return execDocutain('getText');
},
/**
* Detects the text of the currently loaded document and returns it.
*
* @param pageNumber number of the page you want the text from or leave empty to get text of entire document
*/
getTextPage: function (pageNumber) {
return execDocutain('getTextPage',[pageNumber]);
},
/**
* This method sets the analyze configuration.
*
* @param config An instance of AnalyzeConfiguration.
*/
setAnalyzeConfiguration: function (config,) {
return execDocutain('setAnalyzeConfiguration', [config]);
},
/**
* Analyzes the currently loaded document and returns the detected data.
*/
analyze: function () {
return execDocutain('analyze');
},
/**
* This method generates a PDF document from the loaded or scanned pages.
*
* @param fileUri the file uri where to save the PDF document.
* @param overwrite if file already exist, indicate whether to override it or to append number, e.g. TestPDF(1).pdf.
* @param pageFormat the PDF page format, refer to PDFPageFormat.
*/
writePDF: function (pageFormat, fileUri, overwrite) {
return execDocutain('writePDF', [pageFormat, fileUri, overwrite]);
},
/**
* This method sets the log level, which determines the severity of the message.
*
* @param logLevel The Level determining which kind of messages should be logged. The default is Level.Verbose.
*
*/
setLogLevel: function (logLevel) {
return execDocutain('setLogLevel', [logLevel]);
},
/**
* This method returns the Trace file which includes logging and error messages.
*/
getTraceFile: function () {
return execDocutain('getTraceFile');
},
/**
* This method deletes all temporary files created by the Docutain SDK.
*
* @param deleteTraceFileContent If true, the content of the Trace file which you can send us in order to solve any problems will also be deleted
*/
deleteTempFiles: function (deleteTraceFileContent) {
return execDocutain('deleteTempFiles', [deleteTraceFileContent]);
},
/**
* This method generates a JPG from the loaded or scanned page and saves it to a local file.
*
* @param pageNumber the page to be generated as JPG
* @param fileUri the file uri where to save the JPG file
*/
writeImage: function (pageNumber, fileUri) {
return execDocutain('writeImage',[pageNumber, fileUri]);
},
/**
* This method generates a JPG from the loaded or scanned page and returns it as a base64 encoded string.
*
* @param pageNumber the page to be generated as JPG
* @param pageSourceType the PageSourceType type to be used when generating the JPG
*/
getImageBytes: function (pageNumber, pageSourceType) {
return execDocutain('getImageBytes',[pageNumber, pageSourceType]);
},
/**
* This method returns the page count of the currently loaded document.
*/
pageCount: function () {
return execDocutain('pageCount');
},
/**
* Resets onboarding state.
* @param onboarding Opens onboarding on next start
* @param scanHintPopup Opens scanHintPopup on next start.
*/
resetOnboarding: function (onboarding, scanHintPopup){
return execDocutain('resetOnboarding',[onboarding, scanHintPopup]);
},
/**
* Gets the default onboarding items.
*/
onboardingDefaultItems: function() {
return execDocutain('onboardingDefaultItems');
},
/**
* Gets the default scan tips items.
*/
scanTipsDefaultItems: function() {
return execDocutain('scanTipsDefaultItems');
},
/**
* Starts the photo payment process.
* @param config an instance of PhotoPaymentConfiguration.
*/
startPhotoPayment: function(PhotoPaymentConfiguration) {
return execDocutain('startPhotoPayment',[PhotoPaymentConfiguration]);
},
/**
* Gets the default empty result screen items.
*/
emptyResultScreenDefaultItems: function() {
return execDocutain('emptyResultScreenDefaultItems');
}
};