Scenarios
You want to connect the scanner in a Web page, document scanning in a web page. When you scan multiple documents one time, there is a blank page to separate them between each document, and you want to save the document separately in each section of the document after scanning completely.
solution
Use Dynamic Web TWAIN SDK, you can quickly achieve page document scanning using blank pages document separation.
Implementation steps
Step 1: Download and install Dynamic Web TWAIN 30-day free trial version
Application download link: https://www.damingsoft.com/products/dwt-register.aspx
Step 2: build Web pages scanned pages
After installation is complete can in C: \ Program Files (x86) \ Dynamsoft \ Dynamic Web TWAIN SDK {version} Trial \ find a UseEvent.html of Samples \ Getting Started in the sample page. Double-click to open it to achieve the most simple web page scanning.
If you want to build yourself a web page scanning, refer to the documentation: https://www.damingsoft.com/docs/dwt/Dev-Guide/Build-the-Hello-World-Scan-Page.html
Step 3: determine a blank page and save the document
To do this, we will scan all the documents, and then use the interface IsBlankImageExpress (index) to detect whether it is empty. If the page is blank, we will remove it and save the buffer on a set of documents. To accomplish this task, we will use the event OnPostAllTransfers, it triggers the scan is complete, after all, to see if there are any empty page.
At this point, we can open UseEvent.html, its code will be little change. function Dynamsoft_OnReady changes are as follows:
function Dynamsoft_OnReady() {
DWObject = Dynamsoft.WebTwainEnv.GetWebTwain('dwtcontrolContainer'); // Get the Dynamic Web TWAIN object that is embeded in the div with id 'dwtcontrolContainer'
//DWObject.Width = 270; // Set the width of the Dynamic Web TWAIN Object
//DWObject.Height = 400; // Set the height of the Dynamic Web TWAIN Object
if (DWObject) {
DWObject.RegisterEvent('OnPostAllTransfers', CheckBlankPage); // Register OnPostAllTransfers event. This event fires when all pages have been scanned and transferred
}
}
Add function CheckBlankPage:
function CheckBlankPage() { //Function for checking a blank page, called when OnPostAllTransfers is triggered
if (DWObject) {//Ensure there is a DWObject
var startindex = 0;
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) {
i--; //decrement i for the removed image
DWObject.SelectedImagesCount = (i - startindex + 1); // set how many images are selected
for (var j = 0; j < DWObject.SelectedImagesCount; j++) { //loop to select all images from previous blank to current
DWObject.SetSelectedImageIndex(j, j + startindex);
}
if (DWObject.SelectedImagesCount > 0) { //save images as long as there are some in the selection
DWObject.IfShowFileDialog = true;
var randomId = (Math.floor(Math.random() * 1000 + 1)).toString();
DWObject.SaveSelectedImagesAsMultiPagePDF(randomId + ".pdf");//PLEASE CHANGE THIS FILE PATH
}
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
DWObject.SelectedImagesCount = (i - startindex + 1); // set how many images are selected
for (var j = 0; j < DWObject.SelectedImagesCount; j++) { //loop to select all images from previous blank to current
DWObject.SetSelectedImageIndex(j, j + startindex);
}
if (DWObject.SelectedImagesCount > 0) { //save images as long as there are some in the selection
DWObject.IfShowFileDialog = true;
DWObject.SaveSelectedImagesAsMultiPagePDF("AllInOne.pdf");//PLEASE CHANGE THIS FILE PATH
}
}
}
}
}
If your application is difficult to detect a blank page (blank page around the edges of some non-white point), or if you are using a color page, you may need to use the standard deviation of the page. Instead, you can use the following code snippet:
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
//...... same as above code
}
}
}
}
to sum up
Through the above method, you can easily achieve page document scanning, and use the blank pages between documents document separation.
Of course, some application scenarios to separate documents not sign blank pages in a document, but the bar code or two-dimensional code. This is one document separation method, and can be achieved through Dynamic Web TWAIN and add-ons Barcode Reader. We will introduce after the article.