Skip to main content

Document Scan

The Docutain Document Scanner SDK for iOS 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.

ScanEditPreview


Initialization

Initialize the Docutain Xamarin SDK as described here.

Scan with Camera

Camera Permission

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.


NSCameraUsageDescription


Start Camera Scan

To start the scan process you only have to implement our predefined ScanDelegate, implement it's didFinishScan method and call the static UI.scanDocument method at the place you want to start the document scanner, e.g. in a button click handler.

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.

import DocutainSdk

class ViewController: UIViewController, ScanDelegate {

//...

func didFinishScan(withResult result: Bool) {
if(result){
//user finished scan process, continue with your workflow
//generate PDF by using Document.writePDF()
//get detected Text by using DocumentDataReader.getText()
//get data by using DocumentDataReader.analyze()
} else{
//user canceled scan process
}
}

@objc private func scanButtonClicked(){
let scanConfig = DocumentScannerConfiguration()
UI.scanDocument(scanDelegate: self, scanConfig: scanConfig)
}

//...
}

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. Pass sourceImages to the DocumentScannerConfiguration 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.
  • galleryMultiple : 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:

import DocutainSdk

class ViewController: UIViewController, ScanDelegate {

//...

func didFinishScan(withResult result: Bool) {
if(result){
//user finished scan process, continue with your workflow
//generate PDF by using Document.writePDF()
//get detected Text by using DocumentDataReader.getText()
//get data by using DocumentDataReader.analyze()
} else{
//user canceled scan process
}
}

@objc private func scanButtonClicked(){
let scanConfig = DocumentScannerConfiguration()
scanConfig.source = .galleryMultiple
UI.scanDocument(scanDelegate: self, scanConfig: scanConfig)
}

//...
}

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:

  • 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 to illustration. 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
  • pageEditConfig : Configuration class used to alter the default page editing behaviour. See PageEditConfiguration for more details.
  • source : The source of the Document Scanner. Defaults to camera. 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.
info

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:

  • 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.
info

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:

iOS PDF Creation

iOS Text Detection

iOS Data Extraction