Document Scan
The Docutain Document Scanner SDK for Cordova comes with integrated, ready to use UI components for the document scan process. Colors and icons can be changed to match your branding.
It is also possible to use the Document Scanner on imported images.
Initialization
Initialize the Docutain Cordova Scanner SDK as described here.
Scan with Camera
Camera Permission
Android
Declare permissions to use the camera in your in your config.xml
:
<platform name="android">
<config-file target="AndroidManifest.xml" parent="/*">
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera"/>
</config-file>
Runtime permission for camera is handled automatically by the Docutain SDK.
iOS
You need to specify the reason for requesting access to the camera as part of the NSCameraUsageDescription
in the Info.plist
. If you don't the app will crash.
Start Camera Scan
To start the scan process you only have to call DocutainSDK.scanDocument
and wait for it to return.
An instance of DocumentScannerConfiguration
is required to launch the document scanner. It provides the possibility to change some behaviours to adopt it to your needs.
See Change default scan behaviour for possible custom settings.
- Cordova Promisify
- Cordova Callback
async scanDocument(){
const scanConfig = {
//customize the scanner config according to your needs
}
try{
const result = await DocutainSDKPromisify.scanDocument(scanConfig);
if(result.status == "SUCCESS"){
//user finished scan process, continue with your workflow
//generate PDF
const pdfUri = await DocutainSDK.writePDF('A4')
//get detected Text
const text = await DocutainSDK.getText();
//get extracted data
const analyzeData = await DocutainSDK.analyze();
} else if (result.status == "CANCELED"){
//user canceled scan process
}
}
catch(err){
// scan failed
console.error(error);
return;
}
scanDocument(){
const scanConfig = {
//customize the scanner config according to your needs
}
//start the scanner
DocutainSDK.scanDocument(scanConfig, function (result) {
if(result.status == "SUCCESS"){
//user finished scan process, continue with your workflow
...
} else if (result.status == "CANCELED"){
//user canceled scan process
console.log('user canceled scan process');
}
}, error);
Scan from imported images
It is also possible to use the Document Scanner on already taken images, for example images selected from the users photo gallery. The process of starting the scanner on imported images is the same as when scanning with the camera.
The only difference is defining a different Source
in the DocumentScannerConfiguration
. Possible values are:
CAMERA
: This is the default value. Starts the Document Scanner using the devices camera.IMAGE
: Starts the Document Scanner on images provided by you via code. PasssourceImages
to theDocumentScannerConfiguration
containing the paths to the images to be scanned.GALLERY
: Opens the user's photo gallery in single select mode. The Document Scanner is run on the selected image.GALLERY_MULTIPLE
: Opens the user's photo gallery in multi select mode. The Document Scanner is run on the selected images.
The following sample shows how to open the photo gallery in multi select mode and run the Document Scanner on the selected images:
- Cordova Promisify
- Cordova Callback
async scanDocument(){
const scanConfig = {
source: 'GalleryMultiple'
}
try{
const result = await DocutainSDKPromisify.scanDocument(scanConfig);
if(result.status == "CANCELED"){
//user canceled scan process
return;
}
}
catch(err){
// scan failed
console.error(error);
return;
}
//user finished scan process, continue with your workflow
//generate PDF
const pdfUri = await DocutainSDK.writePDF('A4');
//get detected Text
const text = await DocutainSDK.getText()
//get extracted data
const analyzeData = await DocutainSDK.analyze();
scanDocument(){
const scanConfig: DocumentScannerConfiguration = {
source: Source.GalleryMultiple
}
DocutainSDK.scanDocument(options, function (result) {
if(result.status == "SUCCESS"){
//user finished scan process, continue with your workflow
...
} else if (result.status == "CANCELED"){
//user canceled scan process
}
}, error);
}
Change default scan behaviour
DocumentScannerConfiguration
You can use the DocumentScannerConfiguration
to alter the default scan behaviour to your needs. Currently the following values can be set:
DocumentScannerConfiguration {
allowCaptureModeSetting?: boolean;
autoCapture?: boolean;
defaultScanFilter?: ScanFilter;
onboardingImageSource?: string;
pageEditConfig?: PageEditConfiguration;
ColorConfig?: ColorConfig;
source?: Source;
sourceImages?: string[];
autoCrop?: Boolean;
multiPage?: Boolean;
preCaptureFocus?: Boolean;
}
allowCaptureModeSetting
: Defaults to false. If true, the document scanner toolbar will display an item that allows the user to switch between automatic and manual camera triggering.autoCapture
: Defaults to true. If true, the camera will capture the image automatically at the right moment.defaultScanFilter
: Defaults toILLUSTRATION
. The default scan filter that will be used after scan.onboardingImageSource
: Your custom image for the onboarding dialog that appears when scan is opened for the first time. For Android it needs to be the name of an image in your drawable folder. For iOS it needs to be the name of an image in your assets catalog. In both cases do not include file extension.pageEditConfig
: Configuration class used to alter the default page editing behaviour. See PageEditConfiguration for more details.ColorConfig
: Please see Theming for more details.source
: The source of the Document Scanner. Defaults toCAMERA
. If you need to run the scanner on imported images please see Scan from imported images for more details.sourceImages
: Please see Scan from imported images for more details.autoCrop
: Defaults to true. If true, image gets automatically cropped if document was detected. This applies only when importing images.multiPage
: Defaults to true. If true, scanning multi page documents is possible. Set this to false if you need to scan single page documents.preCaptureFocus
: Defaults to true. If true, the camera will run a focus action right before taking the image. This improves the quality of the scanned images, but depending on the device, image capture might take a little bit longer. This applies only to Android.
All parameters in DocumentScannerConfiguration
are optional.
PageEditConfiguration
You can use the PageEditConfiguration
to alter the default page editing behaviour to your needs. Currently the following values can be set:
PageEditConfiguration {
allowPageFilter?: boolean;
allowPageRotation?: boolean;
allowPageArrangement?: boolean;
allowPageCropping?: boolean;
pageArrangementShowDeleteButton?: boolean;
pageArrangementShowPageNumber?: boolean;
}
allowPageFilter
: Defaults to true. If false, the bottom toolbar will hide the filter page item.allowPageRotation
: Defaults to true. If false, the bottom toolbar will hide the rotate page item.allowPageArrangement
: Defaults to true. If false, the bottom toolbar will hide the arrange page item.allowPageCropping
: Defaults to true. If false, the bottom toolbar will hide the page cropping item.pageArrangementShowDeleteButton
: Defaults to false. If true, each item of the page arrangement functionality will show a delete button.pageArrangementShowPageNumber
: Defaults to true. If true, each item of the page arrangement functionality will show it's page number.
All parameters in PageEditConfiguration
are optional.
Result handling
After the scan process is successfully finished, you can do a bunch of things with the scanned pages:
Language Support
The device's locale determines the language used by the Docutain SDK.
Currently, the SDK provides default translations for the following languages:
- English
- Arabic
- Bulgarian
- Chinese, Simplified
- Chinese, Traditional
- Croation
- Czech
- Danish
- Dutch
- Finnish
- French
- German
- Greek
- Hindi
- Hungarian
- Icelandic
- Indonesian
- Italian
- Japanese
- Korean
- Lithuanian
- Norwegian Bokmal
- Polish
- Portugese
- Portugese (Brazil)
- Romanian
- Russian
- Serbian
- Slovak
- Slovenian
- Spanish
- Swedish
- Turkish
The fallback language is English. This means if the device is set to a language that is currently not supported, it will show English texts.
If you think the translation can be improved, please feel free to contact us via support.sdk@Docutain.com.
iOS applications must be localized in XCode by adding each language to the project.