Skip to main content

Scanning a document from an image | Web Document Scanner

async detectDocument(imageBuffer: ArrayBuffer, acceptedAngleScore?: number, acceptedSizeScore?: number): Promise<ContourDetectionResult>
class ContourDetectionResult {
horizontalLines?: MagneticLine[];
verticalLines?: MagneticLine[];
polygon?: Polygon;
detectionStatus?: DetectionStatus;
success?: boolean;
class MagneticLine {
p1: Point;
p2: Point;

Detects document on a still image on JPG file regardless of the image source (e.g. scanned document image, image picked from photo library, etc).

Example usage:

reader.onload = async (e) => {
const result = await scanbotSDK.detectDocument(reader.result);
if (result.success === true) {
} else {

The result object contains the following properties:

  • detectionStatus – DetectionStatus, contains the same keys as the hint texts mentioned earlier
  • success – boolean, whether detection was successful or not
  • original – If success, contains the cropped document ArrayBuffer (UInt8Array)
  • cropped – If success, contains the cropped document ArrayBuffer (UInt8Array)
  • polygon – Polygon, The page's cropping polygon as calculated by a document detection operation
enum DetectionStatus {
NotAcquired = 'NotAcquired',
OK = 'OK',
OK_SmallSize = 'OK_SmallSize',
OK_BadAngles = 'OK_BadAngles',
OK_BadAspectRatio ='OK_BadAspectRatio',
OK_OffCenter = 'OK_OffCenter',
Error_NothingDetected = 'Error_NothingDetected',
Error_Brightness = 'Error_Brightness',
Error_Noise = 'Error_Noise',
type Polygon = [Point, Point, Point, Point];

Want to scan longer than one minute?

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

Get your free Trial License

What do you think of this documentation?