Web Demos

BARCODE READER SDK DEMO

Explore the flexibe barcode reading settings to optimize for your specific usage scenario.

WEB TWAIN SDK DEMO

Try the most popular web scanner features: scan images, import local images and PDF files, edit, save to local, upload to database, and etc.

BARCODE READER JAVASCRIPT DEMO

Transform any camera-equipped devices into real-time, browser-based barcode and QR code scanners.

MRZ SCANNER WEB DEMO

Detects the machine-readable zone of a passport, scans the text, and parses into human-readable data.

APP STORE DEMOS

BARCODE READER SDK FOR IOS

BARCODE READER SDK FOR ANDROID

VIEW MORE DEMOS >
Dev Center
Table of contents

Document Saving

How to use a blank page as a separator?

Scenario

You are scanning in multiple documents with a blank page separating them and would like to save each set of documents separately.

Solution

In order to do this we will scan in all the sheets, then use IsBlankImageExpress to detect whether or not it is blank. If the sheet is blank we will then remove it from the buffer and save the previous set of sheets. In order to accomplish this task we are going to use the event OnPostAllTransfers, which fires after all scans are complete in order to check whether or not any pages are blank.

function Dynamsoft_OnReady() { 
    DWObject = Dynamsoft.DWT.GetWebTwain('dwtcontrolContainer'); // Get the Dynamic Web TWAIN object that is embeded in the div with id 'dwtcontrolContainer' 
    if (DWObject) { 
        DWObject.IfShowUI = false;
        DWObject.IfAutoDiscardBlankpages = false;
        DWObject.RegisterEvent('OnPostAllTransfers', CheckBlankPage); //Register the OnPostAllTransfers event that will be called after all scanning is complete 
    } 
}

function AcquireImage() {
    if (DWObject) {
        DWObject.SelectSource(function () {					
            var OnAcquireImageSuccess = function () {
                DWObject.CloseSource();
            };
            
            var OnAcquireImageFailure = function (ec, es) {
                DWObject.CloseSource();
                alert(es);
            };

            DWObject.OpenSource();
            DWObject.IfDisableSourceAfterAcquire = false;	// Scanner source will be disabled/closed automatically after the scan. 
            DWObject.AcquireImage(OnAcquireImageSuccess, OnAcquireImageFailure);
        }, function () {
            console.log('SelectSource failed!');
        });
    }
}

function OnSuccess() {
    console.log('successful');
}

function OnFailure(errorCode, errorString) {
    alert(errorString);
}

function CheckBlankPage() { //Function for checking a blank page, called when OnPostAllTransfers is triggered
    if (DWObject) { //Ensure there is a DWObject
        var startindex = 0; // Assume it starts from the first page in the buffer.
        for (var i = 0; i < DWObject.HowManyImagesInBuffer; i++) { //Go through each image in the buffer.
            if (DWObject.IsBlankImageExpress(i)) {
                DWObject.RemoveImage(i); // remove the blank page from the buffer.
                if (i != 0) {
                    var imageRecord = [];
                    i--; //decrement i for the removed image
                    var selectedCount = i - startindex + 1;

                    for (var j = 0; j < selectedCount; j++) { //loop to select all images from previous blank to current
                        imageRecord.push(j + startindex);
                    }

                    if (selectedCount > 0) { //save images as long as there are some in the selection
                        DWObject.SelectImages(imageRecord);
                        DWObject.IfShowFileDialog = true;
                        DWObject.SaveSelectedImagesAsMultiPagePDF("C:\\....", OnSuccess, OnFailure); //PLEASE CHANGE THIS FILE PATH (The first parameter)
                    }

                    startindex = i + 1; //set the start index for next search 1 higher than current page
                }
            } else if (i == DWObject.HowManyImagesInBuffer - 1) { //the last few images are not blank
                var selectedCount = i - startindex + 1; // set how many images are selected
                var imageRecord = [];

                for (var j = 0; j < selectedCount; j++) { //loop to select all images from previous blank to current
                    imageRecord.push(j + startindex);
                }

                if (selectedCount > 0) { //save images as long as there are some in the selection
                    DWObject.SelectImages(imageRecord);
                    DWObject.IfShowFileDialog = true;
                    DWObject.SaveSelectedImagesAsMultiPagePDF("C:\\...", OnSuccess, OnFailure); //PLEASE CHANGE THIS FILE PATH (The first parameter)
                }
            }
        }
    }
}

If your application is having a hard time detecting blank pages(there is some areas around the edge of the blank page with non-blank spots) or you are using coloured pages you may want to use the pages standard deviation instead. You may use the following Snippet instead.

Using Page Standard Deviation:

function CheckBlankPage(){ //Function for checking a blank page, called when OnPostAllTransfers is triggered 
    if(DWObject){//Ensure there is a DWObject 
        for(var i = 0; i < DWObject.HowManyImagesInBuffer;i++){//Go through each image in the buffer. 
            if(DWObject.IsBlankImageExpress(i)){}//Make Blank Image run, but do not use the result 
            if(DWObject.BlankImageCurrentStdDev < 15.0){//set a standard deviation for the program to use
                //......
            } 
        } 
    } 
}

Is this page helpful?

YesYes NoNo

In this article:

latest version

    • Latest Version
    • Version 17.2.1
    • Version 17.1.1
    • Version 17.0
    • Version 16.2
    • Version 16.1.1
    Change +
    © 2003–2022 Dynamsoft. All rights reserved.
    Privacy Statement / Site Map / Home / Purchase / Support