Document Scan
The Docutain Document Scanner SDK for Xamarin comes with integrated, ready to use UI components for the document scan process. Colors and icons can be changed to match your branding.
Initialization
Initialize the Docutain Xamarin SDK as described here.
Permissions
- Xamarin.Forms
- Android
- iOS
Android
Declare the following permission in your AndroidManifest.xml
.
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera"/>
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.
Declare permissions to use the camera in your AndroidManifest.xml
:
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera"/>
Runtime permission for camera is handled automatically by the Docutain SDK.
Declare the NSCameraUsageDescription
in the Info.plist
. If you don't the app will crash.
Start the Document Scanner
To start the Document Scanner you only have to call UI.ScanDocument
and wait for it to return.
- Xamarin.Forms
- Xamarin.Android
- Xamarin.iOS
using Docutain.SDK.Xamarin.Forms;
var scanConfig = new DocumentScannerConfiguration();
var result = await UI.ScanDocument(scanConfig);
if(result)
{
//user finished scan process, continue with your workflow
//generate PDF
var destinationPath = FileSystem.CacheDirectory + "/TestPDF.pdf";
var pdf = Document.WritePDF(destinationPath);
//get detected Text
var text = DocumentDataReader.GetText();
//get extracted data
var data = DocumentDataReader.Analyze();
}
else
{
//user canceled scan process
}
using Docutain.SDK.Xamarin.Android;
var scanConfig = new DocumentScannerConfiguration();
var result = await UI.ScanDocument(this, scanConfig);
if(result)
{
//user finished scan process, continue with your workflow
//generate PDF
var destinationPath = FileSystem.CacheDirectory + "/TestPDF.pdf";
var pdf = Document.WritePDF(new Java.IO.File(destinationPath));
//get detected Text
var text = DocumentDataReader.GetText();
//get extracted data
var data = DocumentDataReader.Analyze();
}
else
{
//user canceled scan process
}
using Docutain.SDK.Xamarin.iOS;
var scanConfig = new DocumentScannerConfiguration();
var result = await UI.ScanDocument(scanConfig);
if(result)
{
//user finished scan process, continue with your workflow
//generate PDF
var paths = NSFileManager.DefaultManager.GetUrls(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User);
var destinationPath = paths[0];
var pdf = Document.WritePDF(destinationPath, "TestPDF");
//get detected Text
var text = DocumentDataReader.GetText();
//get extracted data
var data = DocumentDataReader.Analyze();
}
else
{
//user canceled scan process
}
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.
var scanConfig = new DocumentScannerConfiguration();
scanConfig.AllowCaptureModeSetting = true; // defaults to false
scanConfig.PageEditConfig.AllowPageFilter = false; // defaults to true
scanConfig.PageEditConfig.AllowPageRotation = false; // defaults to true
// Further customization options available ...
All parameters in DocumentScannerConfiguration are optional.
Result handling
After the scan process is successfully finished, you can do a bunch of things with the scanned pages: