Cleaning up documents with the Android Document Scanner
Document Cleanup lets the end user erase unwanted artifacts from a scanned page while preserving the underlying document content. Artifacts include handwriting, stamps, stains, fingers, shadows, and other distracting elements. The user paints over the regions to remove. The SDK then reconstructs a clean result image, with optional text preservation.
The Scanbot SDK ships a ready-to-use composable, DocumentCleanupCustomUI, that wraps the classic DocumentCleanup API and exposes brush controls, undo / redo / reset actions, pinch-to-zoom, and progress reporting. The host application stays in full control of the surrounding chrome (top bar, toolbar, buttons, sliders, etc.).
Usage of the Document Cleanup composable
The composable receives the page image as an ImageRef and renders an interactive canvas on top of it. Capture the DocumentCleanupActionController via onActionControllerCreated to trigger undo(), redo(), and reset() programmatically and to observe canUndo, canRedo, and progress.
loading...
Configuration options
Configure the cleanup behavior of the underlying engine through DocumentCleanupConfiguration. In the Ready-to-Use UI, pass it as screens.cleanup.engineConfiguration.
| Property | Type | Default | Description |
|---|---|---|---|
keepText | Boolean | true | If true, the SDK keeps detected text intact while the user erases around it. Text detection runs once up front and can take a moment, so construct the cleanup pipeline asynchronously to keep the UI responsive. |
maxUndoRedoStackSize | Int | 10 | How many undo and redo steps the SDK keeps in memory. Use at least 1 so that reset can always restore the original image. When the limit is reached, the SDK merges the two oldest steps into one. The user can still return to the original image, but with fewer steps in between. |
maxCleanupResolution | Int | 0 | Caps the brushed area the SDK processes in one cleanup step, as width × height in pixels. Larger areas are processed at a lower resolution and scaled back up, which saves memory but can soften the edges near the stroke. 0 means no limit. For example, 1200000 keeps peak memory at about 0.5 GB for a 12 MP image. Prefer cleaning smaller areas over relying on this limit. |
Cleanup status
A cleanup run reports a DocumentCleanupStatus alongside the resulting image:
| Value | Meaning |
|---|---|
OK | Cleanup completed at full resolution. |
OK_BUT_REDUCED_QUALITY | Cleanup completed, but maxCleanupResolution forced an internal downscale of the cleanup region, so quality near the cleanup boundary may be reduced. If the result is not good enough, undo the last operation and apply cleanup on a smaller area. |
Composable parameters
In addition to documentCleanupConfiguration, DocumentCleanupCustomUI exposes the following parameters to customize appearance and interaction:
image— the sourceImageRefto be cleaned up.backgroundColor— color rendered behind the image canvas.brushSize— diameter of the drawing brush (indp).brushColor— brush stroke preview color.maxZoomScale— maximum zoom factor supported by pinch-to-zoom.onActionControllerCreated— receives theDocumentCleanupActionControllerused to triggerundo()/redo()/reset()and to observecanUndo,canRedoandprogress.onResultImageChanged— invoked after every successful cleanup, undo, redo or reset with the new resultImageRef. The composable owns that image, so don't close it.onProgressChanged— invoked withtruewhen a heavy cleanup operation starts andfalsewhen it finishes; use it to drive a progress indicator.onError— invoked on SDK setup or cleanup failures.
Want to scan longer than one minute?
Generate a free trial license to test the Scanbot SDK thoroughly.
Get free trial licenseScanbot SDK is part of the Apryse SDK product family
A mobile scan is just the start. With Apryse SDKs, you can expand mobile workflows into full cross‑platform document processing. Whether you need to edit PDFs, add secure digital signatures, or use a fast, customizable document viewer and editor, Apryse gives you the tools to build powerful features quickly.
Learn more
