Skip to main content

Cleaning up documents with the Web 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 DocumentCleanupView component that renders the page image, handles the brush strokes and pinch-to-zoom gestures, and wraps the underlying DocumentCleanup engine. The component is opened and controlled through an IDocumentCleanupViewHandle, which exposes the cleanup actions (apply, undo, redo, reset, ...).

Creating the Cleanup view​

Create a DocumentCleanupViewConfiguration with the target container element ID, the page image, and, optionally, a DocumentCleanupConfiguration for the underlying engine. Pass it to scanbotSDK.openDocumentCleanupView() to create and mount the view.

Creating the Document Cleanup View
loading...

You should store the returned handle in a globally accessible location, as all further cleanup functions are called on it.

Usage of the Document Cleanup view​

Paint over the areas to remove directly on the view, call apply() to run the cleanup engine on the current brush strokes; it returns a DocumentCleanupResult with the resulting image and a status (see below), and clears the brush strokes from the canvas. Call undo() / redo() to step through the cleanup history, and reset() to discard all cleanup operations and restore the original image. Use canUndo() / canRedo() to enable or disable your own controls.

Using the Document Cleanup View
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.

View configuration and handle reference​

In addition to image and cleanupConfiguration, DocumentCleanupViewConfiguration exposes:

  • style.padding — padding, in pixels, around the image inside the view container.
  • style.brush.size — diameter of the drawing brush, relative to the displayed image size.
  • style.brush.color — color of the stroke overlay drawn while the user paints.
  • onMaskApplied — called each time a cleanup mask is built and sent to the engine; receives the full-resolution binary mask image.
  • onStrokeCompleted — called when a brush stroke is completed; use it to trigger apply().
  • onPinchStart / onPinchEnd — called when a two-finger pinch gesture starts or ends on the view.

IDocumentCleanupViewHandle exposes the following methods:

  • updateConfiguration(config) — deep-merges a partial configuration into the active one and re-renders the view.
  • apply() — applies the current brush strokes as a cleanup mask and returns the resulting DocumentCleanupResult.
  • undo() / redo() — step through the cleanup history; each returns the resulting image.
  • reset() — clears all brush strokes and cleanup operations, restoring the original image.
  • canUndo() / canRedo() — whether an undo or redo step is currently available.
  • clearBrushStrokes() — clears the current, not-yet-applied brush strokes without running cleanup.
  • dispose() — unmounts the view and releases its resources.

Want to scan longer than one minute?

Generate a free trial license to test the Scanbot SDK thoroughly.

Get free trial license