SDK Features | .NET MAUI Document Scanner
Document Scanning
The Scanbot SDK uses digital image processing algorithms to find rectangular, document like polygons in a digital image.
As input a UIImage
on iOS or Bitmap
on Android are accepted.
- MAUI
- .NET Android
- .NET iOS
Launches the Document Scanner. The scanned pages will be returned asynchronously.
loading...
loading...
loading...
loading...
loading...
Image Cropping
- MAUI
- .NET Android
- .NET iOS
loading...
Launch the CroppingActivity
using below snippet.
loading...
Handle the result in the OnActivityResult()
loading...
Launch the SBSDKUICroppingViewController
using below snippet.
loading...
Handle the results in the implementation of SBSDKUICroppingViewControllerDelegate
.
loading...
Image Filtering
- MAUI
- .NET Android
- .NET iOS
loading...
Supported image filters:
ImageFilter.ColorEnhanced
- Optimizes colors, contrast and brightness.ImageFilter.Grayscale
- Grayscale filterImageFilter.Binarized
- Standard binarization filter with contrast optimization. Creates an 8-bit grayscale image with mostly black or white pixels.ImageFilter.ColorDocument
- MagicColor filter. Fixes white balance and cleans up the background.ImageFilter.PureBinarized
- A filter for binarizing an image. Creates an image with pixel values set to either pure black or pure white.ImageFilter.BackgroundClean
- Cleans up the background and tries to preserve photos within the image.ImageFilter.BlackAndWhite
- Black and white filter with background cleaning. Creates an 8-bit grayscale image with mostly black or white pixels.ImageFilter.OtsuBinarization
- A filter for black and white conversion using OTSU binarization.ImageFilter.DeepBinarization
- A filter for black and white conversion primary used for low contrast documents.ImageFilter.EdgeHighlight
- A filter that enhances edges in low contrast documents.ImageFilter.LowLightBinarization
- A binarization filter primarily intended for use on low contrast documents with hard shadows.
Page page = ...;
var filter = new ColorDocumentFilter();
pageProcessor.ApplyFilter(page, filter);
For more information on the parametric filters, please refer to the API references here.
Supported parametric image filters:
ColorDocumentFilter
- Color document filter. This filter is a good starting point for most use cases.ScanbotBinarizationFilter
- Automatic binarization filter. This filter is a good starting point for most use cases. It hasoutputMode: OutputMode
parameter which can be set toOutputMode.BINARY
orOutputMode.ANTIALIASED
.CustomBinarizationFilter
- Customizable binarization filter. It has a few presets for specific use cases:BinarizationFilterPreset.PRESET_1
- Usually performs well if there is no shadow.BinarizationFilterPreset.PRESET_2
,BinarizationFilterPreset.PRESET_3
,BinarizationFilterPreset.PRESET_4
- Usually performs well even if there are shadows.
BrightnessFilter
- Brightness adjustment filter.ContrastFilter
- Contrast adjustment filter.GrayscaleFilter
- Converts color images to grayscale, optionally applying auto-contrast.WhiteBlackPointFilter
- Maps image value channel so that all the pixels darker than the black point are set to 0, all the pixels brighter than the white point are set to 255, and the pixels in between are linearly scaled.LegacyFilter
- A filter that applies a legacy filter to the image. This filter is used for compatibility with older versions of the Scanbot SDK. It takes one of the old filter types as a parameter:ImageFilterType.None
- Do not apply an image filter, keep the original colors.ImageFilterType.ColorEnhanced
- Optimizes the colors, contrast and brightness.ImageFilterType.Grayscale
- Grayscale filter.ImageFilterType.Binarized
- Standard binarization filter with contrast optimization. Creates an 8-bit grayscale image with mostly black or white pixels.ImageFilterType.ColorDocument
- MagicColor filter. Fixes the white-balance and cleans up the background.ImageFilterType.PureBinarized
- A filter for binarizing an image. Creates an image with pixel values set to either pure black or pure white.ImageFilterType.BlackAndWhite
- Black and white filter with background cleaning. Creates an 8-bit grayscale image with mostly black or white pixels.ImageFilterType.BackgroundClean
- Cleans up the background and tries to preserve photos within the image.ImageFilterType.OtsuBinarization
- A filter for black and white conversion using OTSU binarization.ImageFilterType.DeepBinarization
- A filter for black and white conversion primary used for low-contrast documents.ImageFilterType.EdgeHighlight
- A filter that enhances edges in low-contrast documents.ImageFilterType.LowLightBinarization
- Binarization filter primarily intended to use on low-contrast documents with hard shadows.ImageFilterType.LowLightBinarization2
- Binarization filter primarily intended to use on low-contrast documents with hard shadows.ImageFilterType.SensitiveBinarization
- Binarization filter for poor quality printed papers. See important info about this type below!
Page page = ...;
var filter = new SBSDKColorDocumentFilter();
pageProcessor.ApplyFilter(page, filter);
For more information on the parametric filters, please refer to the API references here.
Supported parametric image filters:
SBSDKColorDocumentFilter
- Color document filter. This filter is a good starting point for most use cases.SBSDKScanbotBinarizationFilter
- Automatic binarization filter. This filter is a good starting point for most use cases. It hasSBSDKOutputMode
parameter which can be set tobinary
orantialiased
.SBSDKCustomBinarizationFilter
- Customizable binarization filter. It has a few presets for specific use cases:SBSDKBinarizationFilterPreset.preset1
- Usually performs well if there is no shadow.SBSDKBinarizationFilterPreset.preset2
,SBSDKBinarizationFilterPreset.preset3
,SBSDKBinarizationFilterPreset.preset4
- Usually performs well even if there are shadows.
SBSDKBrightnessFilter
- Brightness adjustment filter.SBSDKContrastFilter
- Contrast adjustment filter.SBSDKGrayscaleFilter
- Converts color images to grayscale, optionally applying auto-contrast.SBSDKWhiteBlackPointFilter
- Maps image value channel so that all the pixels darker than the black point are set to 0, all the pixels brighter than the white point are set to 255, and the pixels in between are linearly scaled.SBSDKLegacyFilter
- A filter that applies a legacy filter to the image. This filter is used for compatibility with older versions of the Scanbot SDK. It takes one of the old filter types as a parameter:SBSDKImageFilterType.None
- Do not apply an image filter, keep the original colors.SBSDKImageFilterType.ColorEnhanced
- Optimizes the colors, contrast and brightness.SBSDKImageFilterType.Grayscale
- Grayscale filter.SBSDKImageFilterType.Binarized
- Standard binarization filter with contrast optimization. Creates an 8-bit grayscale image with mostly black or white pixels.SBSDKImageFilterType.ColorDocument
- MagicColor filter. Fixes the white-balance and cleans up the background.SBSDKImageFilterType.PureBinarized
- A filter for binarizing an image. Creates an image with pixel values set to either pure black or pure white.SBSDKImageFilterType.BlackAndWhite
- Black and white filter with background cleaning. Creates an 8-bit grayscale image with mostly black or white pixels.SBSDKImageFilterType.BackgroundClean
- Cleans up the background and tries to preserve photos within the image.SBSDKImageFilterType.OtsuBinarization
- A filter for black and white conversion using OTSU binarization.SBSDKImageFilterType.DeepBinarization
- A filter for black and white conversion primary used for low-contrast documents.SBSDKImageFilterType.EdgeHighlight
- A filter that enhances edges in low-contrast documents.SBSDKImageFilterType.LowLightBinarization
- Binarization filter primarily intended to use on low-contrast documents with hard shadows.SBSDKImageFilterType.LowLightBinarization2
- Binarization filter primarily intended to use on low-contrast documents with hard shadows.SBSDKImageFilterType.SensitiveBinarization
- Binarization filter for poor quality printed papers.
Detect Document Quality
- MAUI
- .NET Android
- .NET iOS
loading...
Document Quality result:
VeryPoor
- The quality of the document is very poor.Poor
- The quality of the document is poor.Reasonable
- The quality of the document is reasonable.Good
- The quality of the document is good.Excellent
- The quality of the document is excellent.
loading...
Please refer to the API reference docs for Document quality result.
loading...
Please refer to the API reference docs for Document quality result.
However, this is not as easy as it seems. If a scanned document has a predominantly white background, it will be considered a very poor image. It is therefore best to check the document quality on a pre-cropped document.
Creating PDF Documents
The Scanbot SDK renders images into a PDF document and stores it as a given target file. For each image a separate page is generated.
- MAUI
- .NET Android
- .NET iOS
Task<Uri> CreatePdfAsync(IEnumerable<FileImageSource> files, PDFPageSize pageSize = PDFPageSize.Custom, PDFPageOrientation pdfPageOrientation = PDFPageOrientation.Auto, OcrConfig configuration = null);
Creates a PDF file out of one or more FileImageSource
objects. All images must be instances of FileImageSource
.
These are images created with ImageSource.FromFile
and images stored as files by the Scanbot MAUI SDK.
If more than one image is given, the function creates a multi-page PDF.
The generated PDF file will be deleted when calling CleanUp. If you want to keep the file, move it to a folder that you have control over.
Typically, the final hi-res document image files of the scanned Page
s (Page.Document
) are used to generate the PDF file.
loading...
Input args:
files
: Input images as a list ofFileImageSource
s in proper order (image element 1 => page 1, etc).configuration
:PDFConfiguration
object which contains information about the PDF and its metadata. Please refer to the detailed points for this object below.
Result:
pdfFileUri
: FileUri
of the PDF result file ('file:///...'
).
The following PDF page sizes are supported:
Supported PDF Page Sizes
Letter
: The page has US letter size: 8.5x11 inches. The image is fitted and centered within the page.Legal
: The page has US legal size: 8.5x14 inches. The image is fitted and centered within the page.A3
: The page has A3 size: 297x420 mm. The image is fitted and centered within the page.A4
: The page has the aspect ratio of the image, but is fitted into A4 size. Whether portrait or landscape depends on the images aspect ratio.A5
: The page has A5 size: 148x210 mm. The image is fitted and centered within the page.B4
: The page has B4 size: 250x353 mm. The image is fitted and centered within the page.B5
: The page has B5 size: 176x250 mm. The image is fitted and centered within the page.Executive
: The page has US executive size: 7.25x10.5 inches. The image is fitted and centered within the page.US4x6
: The page has US 4x6 size: 4x6 inches. The image is fitted and centered within the page.US4x8
: The page has US 4x8 size: 4x8 inches. The image is fitted and centered within the page.US5x7
: The page has US 5x7 size: 4x6 inches. The image is fitted and centered within the page.Comm10
: The page has COMM10 size: 4.125x9.5 inches. The image is fitted and centered within the page.Custom
: Each page is as large as its image at 72 dpi.
Supported Page Orientations
Auto
Portrait
Landscape
PdfAttributes
This objects allows the user to set the below metadata values for the PDF.
Author
Creator
Title
Subject
Keywords
Creating PDF with Metadata.
loading...
Please refer to the API references for the PdfConfig.
Creating PDF
loading...
Adding PDF Metadata
loading...
Please refer to the API references for the SBSDKPDFRendererOptions.
If you need to generate a searchable PDF file with a text layer, please refer to the "OCR" section.
Creating Sandwich PDF Document
This functionality allows the user to create a Sandwich PDF document. It creates a PDF document along with performing Optical Character Recognition (OCR).
Please refer to the code sample below to create a Sandwich PDF.
- MAUI
- .NET Android
- .NET iOS
loading...
loading...
loading...
loading...
loading...
Creating TIFF Documents
- MAUI
- .NET Android
- .NET iOS
Task<Uri> WriteTiffAsync(IEnumerable<FileImageSource> files, TiffOptions options = null)
Writes the given images into a TIFF file. All images must be instances of FileImageSource
.
These are images created with ImageSource.FromFile
and images stored as files by the Scanbot MAUI SDK.
If more than one image is given, the function creates a multi-page TIFF.
The function can optionally create a 1-bit encoded (binarized) TIFF.
The generated TIFF file will be deleted when calling CleanUp. If you want to keep the file, move it to a folder that you have control over.
Typically, the final hi-res document image files of the scanned Page
s (Page.Document
) are used to generate the TIFF file.
loading...
Input args:
images
: Input images as a list ofFileImageSource
s in proper order (image element 1 => page 1, etc).options
: optionalTiffOptions
:OneBitEncoded
: Optional boolean flag. Iftrue
, the input images will be binarized and the output TIFF file will be saved with one bit per pixel. Iffalse
, the input images will be stored as-is. The default value is false.Dpi
: Optional integer value for Dots Per Inches. The default value is200
dpi.Compression
: Optional TIFF compression type. The default value depends on theOneBitEncoded
flag.CompressionCcittT6
(CCITT Fax 4) is the default value for binarized (OneBitEncoded=true
) images. For color images (OneBitEncoded=false
) the default value isCompressionAdobeDeflate
(ZIP).
Result:
tiffFileUri
: File URI of the TIFF result file ('file:///...'
).
Supported TIFF Compression Types
CompressionNone
: No compression.CompressionCcittT6
: "CCITT Fax 4" compression type. Most common and recommended type for binarized (1-bit) black and white images to achieve a small TIFF file size.CompressionAdobeDeflate
: "ZIP" compression type. Most common type for color images.CompressionCcittrle
CompressionCcittfax3
CompressionCcittT4
CompressionCcittfax4
CompressionCcittrlew
CompressionLzw
CompressionPackbits
CompressionDeflate
loading...
Please refer to the API reference docs for more details regarding:
- CreateTiffWriter from the ScanbotSDK instance
- Function WriteTIFFFromFiles
- TIFF parameters TIFFImageWriterParameters
- Supported TIFFImageWriterCompressionOptions
loading...
loading...
Please refer to the API reference docs for more details regarding:
- SBSDKTIFFImageWriter
- Function WriteTIFFFromToFile
- TIFF parameters SBSDKTIFFImageWriterParameters
- Supported SBSDKTIFFImageWriterCompressionOptions
Please note that the following compression types are only compatible for binarized images (1-bit encoded black & white images):
CompressionCcittrle
, CompressionCcittfax3
, CompressionCcittT4
, CompressionCcittfax4
, CompressionCcittT6
, CompressionCcittrlew
.
Page Model
The Scanbot SDK provides a ready-to-use UI for document scanning and cropping. Both components use the notion of a 'page' as a data model for the scanning and cropping activities.
Pages are stored in an internal page file storage, where the pageId
serves as a name prefix for the stored image files. Operations that modify pages work in-place. That is, for example, RotatePage()
overwrites the page's image files with their rotated versions. This behavior differs from the behavior of raw image functions like RotateImage()
which always create a new file.
- MAUI
- .NET Android
- .NET iOS
A page is represented by ScanbotSDK.MAUI.Services.IScannedPage
.
IScannedPage
implements INotifyPropertyChanged
and can be directly used as a BindingContext
.
A page is represented by IO.Scanbot.Sdk.Persistence.Page
To retrieve the page object from the page storage:
var pageId = ... // pageId from the storage
var scanbotSDK = new IO.Scanbot.Sdk.ScanbotSDK(this);
var pageStorage = scanbotSDK.CreatePageFileStorage();
var page = new Page().Copy(pageId: selectedPageId);
A page is represented by ScanbotSDK.iOS.SBSDKDocumentPage
To retrieve the page object from the page storage:
var pageId = ... // pageId from the storage
var pagePolygons = ... // saved polygons. It can be null.
var page = new SBSDKDocumentPage(pageId, pagePolygons);
Persistence of Page Objects
Scanbot SDK does not persist page objects, only the image files (.jpg or .png). The management of page objects and the persistence of the page metadata is left to the app. Depending on the use case, it may be necessary to persist the data of the page objects in the app (e.g. as JSON in a local SQLite database). If this is the case, the following must be considered.
The Page objects contain absolute paths to the image files, i.e. the Document
image of a ScannedPage
might be located at:
file:///var/mobile/Containers/Data/Application/54286F82-A8F7-4850-A684-8D3487726A4D/Library/Application%20Support/net.doo.ScanbotSDK/SBSDK_ImageStorage_Default/PageFileStorage/JPEG/documents/60426F47-4119-48F8-ADA9-F7E60D583CB4_preview.jpg
The page image files are stored in corresponding storage locations. By default, the Scanbot SDK Android uses the internal files directory of the app, whereas the Scanbot SDK iOS uses the "Application Support" folder. Those storage folders are secure and are not affected by an app update.
However, on iOS, the absolute file path of the "Application Support" folder is not reliable.
For each fresh install of an app, a new UUID is generated, in the following format:
/var/mobile/Containers/Data/Application/{UUID}
. That is where application data is stored.
When updating the app, the uuid may change. For example:
Before an app update:
file:///var/mobile/Containers/Data/Application/54286F82-A8F7-4850-A684-8D3487726A4D/Library/Application%20Support/net.doo.ScanbotSDK/SBSDK_ImageStorage_Default/PageFileStorage/JPEG/documents/60426F47-4119-48F8-ADA9-F7E60D583CB4.jpg
After the app update:
file:///var/mobile/Containers/Data/Application/C9181555-252A-4665-892F-793008ED0EDD/Library/Application%20Support/net.doo.ScanbotSDK/SBSDK_ImageStorage_Default/PageFileStorage/JPEG/documents/60426F47-4119-48F8-ADA9-F7E60D583CB4.jpg
Please note that the actual image files are still there, only the absolute file paths change.
To get to the new absolute paths, the API method RefreshImageUris(IEnumerable<IScannedPage>)
has been introduced in the ScanbotSDK.MAUI package. Please use this method to refresh all image file URIs from affected pages:
List<IScannedPage> loadedPages = // load pages from database
var refreshedPages = await ScanbotSDK.SDKService.RefreshImageUris(loadedPages);
It is highly recommended to use this method whenever you have to (re-)load Page objects from the database of your app, regardless of whether there was an app update or not.
Storage and Encryption
Creating Storage
- MAUI
- .NET Android
- .NET iOS
loading...
loading...
loading...
loading...
loading...
loading...
Encryption
Scanbot SDK provides the ability to store the generated image files (JPG, PNG) and PDF files encrypted. This feature provides an additional level of security to the default secure storage locations of the native SDKs.
By default the file encryption is disabled. If you use ScanbotSDK wrapper, you have to pass the following config parameters on SDK initialization:
- MAUI
- .NET Android
- .NET iOS
loading...
var initializer = new IO.Scanbot.Sdk.ScanbotSDKInitializer();
var processor = new AESEncryptedFileIOProcessor(
"SomeSecretPa$$w0rdForFileEncryption",
AESEncryptedFileIOProcessor.AESEncrypterMode.Aes256
);
initializer.UseFileEncryption(true, processor);
First implement the SBSDKStorageCrypting
interface:
var encrypter = new SBSDKAESEncrypter("S0m3W3irDL0ngPa$$w0rdino!!!!",
SBSDKAESEncrypterMode.SBSDKAESEncrypterModeAES128);
ScanbotSDKUI.DefaultImageStoreEncrypter = encrypter;
ScanbotSDKUI.DefaultPDFEncrypter = encrypter;
By activating the storage encryption the native Scanbot SDKs will use the built-in AES 128 or AES 256 encryption. All generated image files (JPG, PNG) including the preview image files, as well as the exported PDF files will be encrypted in memory and stored as encrypted data files on the flash storage of the device.
The Scanbot SDK derives the AES key from the given password, an internal salt value, and the internal number of iterations using the PBKDF2 function.
When applying image operations like cropping, rotation or image filters, Scanbot SDK will decrypt the image file in memory, apply the changes, encrypt and store it again.
What do you think of this documentation?
What can we do to improve it? Please be as detailed as you like.