Skip to main content

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.

Document Cleanup Custom UI Composable
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.

PropertyTypeDefaultDescription
keepTextBooleantrueIf 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.
maxUndoRedoStackSizeInt10How 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.
maxCleanupResolutionInt0Caps 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:

ValueMeaning
OKCleanup completed at full resolution.
OK_BUT_REDUCED_QUALITYCleanup 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 source ImageRef to be cleaned up.
  • backgroundColor — color rendered behind the image canvas.
  • brushSize — diameter of the drawing brush (in dp).
  • brushColor — brush stroke preview color.
  • maxZoomScale — maximum zoom factor supported by pinch-to-zoom.
  • onActionControllerCreated — receives the DocumentCleanupActionController used to trigger undo() / redo() / reset() and to observe canUndo, canRedo and progress.
  • onResultImageChanged — invoked after every successful cleanup, undo, redo or reset with the new result ImageRef. The composable owns that image, so don't close it.
  • onProgressChanged — invoked with true when a heavy cleanup operation starts and false when 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 license