Which method to make the device asking for more document to scan?

Questions, comments and suggestions concerning VintaSoft Twain .NET SDK.

Moderator: Alex

Post Reply
mywebforall
Posts: 15
Joined: Wed Mar 01, 2023 2:35 pm

Which method to make the device asking for more document to scan?

Post by mywebforall »

Hi Alex,
could you tell me if your plugin has a way (when scanning from ADF or not) to ask if there are more papers to scan?
If I red properly, it has something to do with WebAcquireModalStateEnumJS, but i was not able to find a function or a method in your Documentation to help me understand it or doing it.
Thank you .
Luigi
Alex
Site Admin
Posts: 2305
Joined: Thu Jul 10, 2008 2:21 pm

Re: Which method to make the device asking for more document to scan?

Post by Alex »

Hi Luigi,

You can set count of images to scan using the WebTwainDeviceJS.set_XferCount function.

0 means that TWAIN scanner should scan all images from document feeder, 1 means that TWAIN scanner should scan 1 image, 2 means that TWAIN scanner should scan 2 images, etc.

Best regards, Alexanader
mywebforall
Posts: 15
Joined: Wed Mar 01, 2023 2:35 pm

Re: Which method to make the device asking for more document to scan?

Post by mywebforall »

Hi Alex,

Do you mean that if for example i set the count to 2, after two papers it asks for more? Or it stops to scan?
When i set twainDevice.open(true, true), in the UI dialog of the scanner there is a checkbox telling the device to ask if there are more papers to scan.
I want to achieve the same result without showing the UI.

Thank you,
Luigi
Alex
Site Admin
Posts: 2305
Joined: Thu Jul 10, 2008 2:21 pm

Re: Which method to make the device asking for more document to scan?

Post by Alex »

If you set XferCount to 2, TWAIN scanner will acquire 2 images and will stop image scanning.

If you want to ask more paper when feeder is empty, you can go by the following way:
  • Set XferCount to 0 and start image scanning => TWAIN scanner will process all pages in document feeder.
  • Ask for more pages.
  • Start new image scanning process if user added pages to the document feeder.
Best regards, Alexander
mywebforall
Posts: 15
Joined: Wed Mar 01, 2023 2:35 pm

Re: Which method to make the device asking for more document to scan?

Post by mywebforall »

Sorry Alex,

maybe i'm too dumb, but how can i ask for more pages? Is there a specifc method for do this?
Wht i would achieve is this:

1 Step : Start scanning whatever the source is :ADF or Flatbed.
2 Step : Once finished the 1 Step, prompt a dialog : "End the scanning here or load more papers and continue?"

Right now the XferCount is set to 0 by default and scanning goes on till the feeder is empty, does not ask for more, closes it and sends the file to an ftp server as i set it. The same is for the Flatbed.
I've tried to add a 3rd Case(where i set acquireModalState = 2) to the Do While of acquireModalState to ask for more paper to be fed and on confirm, restart the loop from beginning. The problem is that, got on the 3rd case, the loop won't begin again and always reaches the acquireModalState == 0.

Do you have any method or way to handle the Do While of acquireModalState ?

-----------------------------------------------OR-------------------------------------------------------

Are there, in your plugin, built-in methods to achieve the Step 1 and 2 listed before ?

This is the last big issue i've to resolve before finishing my Web App and buy your license.

Thanks,
Luigi
Alex
Site Admin
Posts: 2305
Joined: Thu Jul 10, 2008 2:21 pm

Re: Which method to make the device asking for more document to scan?

Post by Alex »

Hi Luigi,

You need to implement the following logic:
  • Open TWAIN device.
  • Acquire images from document feeder.
  • Close TWAIN device.
  • Ask user if he wants to continue scanning.
  • Open TWAIN device.
  • Acquire images from document feeder.
  • Close TWAIN device.
Best regards, Alexander
mywebforall
Posts: 15
Joined: Wed Mar 01, 2023 2:35 pm

Re: Which method to make the device asking for more document to scan?

Post by mywebforall »

Hi Alex,

Using promises and global variable storage, i managed to get a dialog asking for more papers and to restart the scanning. Now the issue is about finishing the process on End Dialog's button. When the user presses it, i got an error :
Error: Image with identifier: 'bla bla bla' is not found
I suppose it's thrown by the self.acquiredImages.getAsBase64String() function, i think because everytime the user confirms for continuing scanning, it keeps the IDs but not the relative previous scanned images.

here is my actual code :

Code: Select all


//Triggering the Scanning Process
        self.managerDOM.find(".scan_btn").each(function () {
            var item = $(this);

            item.click(async function (e) {
                var dateScan = self.getTime();
                var nomeFile = item.text() + '_' + dateScan;
                console.log(nomeFile)
                self.scanMore = true;

                self.acquiredImages = new Vintasoft.Twain.WebAcquiredImageCollectionJS(self.twainDeviceManager);

                while (self.scanMore == true) await self.__synchronouslyAcquireImagesFromTwainScannerAndSaveToPdfFile(self.selectedDevice, nomeFile);
            });
        });

//Scanning Function
 __synchronouslyAcquireImagesFromTwainScannerAndSaveToPdfFile(selectedDevice, nome_file) {
        var self = this;

        var twainDevice = selectedDevice;

        return new Promise(async function (resolve, reject) {
            try {

                // open TWAIN device manager
                self.twainDeviceManager.open(self.twainDeviceManagerInitSettingsJS);

                // // get the default TWAIN device
                // twainDevice = twainDeviceManager.get_DefaultDevice();

                // open TWAIN device (display device UI and display dialog with image scanning progress)

                twainDevice.open(false, true);
                // specify that grayscale images must be acquired from TWAIN scanner
                twainDevice.set_PixelType(new Vintasoft.Twain.WebPixelTypeEnumJS("Gray"));

                // create collection for images acquired from TWAIN scanner
                // var acquiredImages = new Vintasoft.Twain.WebAcquiredImageCollectionJS(self.twainDeviceManager);

                var acquireModalState;
                //var savedImageCount = 0;
                do {
                    // do one step of modal image acquisition process
                    var acquireModalResult = twainDevice.acquireModalSync();
                    l(acquireModalResult);
                    // get state of image acquisition
                    acquireModalState = acquireModalResult.get_AcquireModalState().valueOf();
                    l('acquiremodalstate');
                    l(acquireModalState);

                    switch (acquireModalState) {
                        case 2:   // image is acquired
                            // get acquired image
                            var acquiredImage = acquireModalResult.get_AcquiredImage();
                            // add acquired image to the collection of acquired images
                            self.acquiredImages.add(acquiredImage);
                            // save acquired image to "result.pdf" file
                            console.log(self.acquiredImages);
                            
                            break;

                        case 4:   // scan is failed
                            alert(acquireModalResult.get_ErrorMessage());
                            break;
                        case 9:   // scan is finished
                            let result = await swalConfirm('Continuare la scansione?', 'Si', 'No');
                            if (result.isConfirmed) {
                                self.scanMore = true;
                                // resolve();
                                break;
                            } else {
                                self.scanMore = false;
                                let params = {};
                                var imageIds = [];
                                const c = self.acquiredImages.get_Count();
                                l('Const c: '+c);
                                // for each acquired image
                                for (var i = 0; i < c; i++) {
                                    // add image identifier to array of image identifiers
                                    imageIds.push(self.acquiredImages.getItem(i).get_Id());
                                    l('Acquired image id: ' + self.acquiredImages.getItem(i).get_Id());
                                    l('Acquired image getitem[i]: '+self.acquiredImages.getItem(i));
                                    l('Selfacquiredimages: '+self.acquiredImages);
                                }
                                l('Image ids');
                                l(imageIds);
                                // save images to an image file and return file data as a Base64 string
                                
                                var imageFileAsBase64String = self.acquiredImages.getAsBase64String(nome_file + '.pdf', imageIds);
                                // l(imageFileAsBase64String);
                                params.fileToUpload = imageFileAsBase64String;
                                params.nomeFile = nome_file;
                                let connection = new Connection('scansioni/pdfupload', params, true);
                                connection.go().then(function (response) {
                                    if (response.result == "success") {
                                        alert("Scansione caricata con successo");
                                        self.initLoadListaPdfUtente();
                                        let PDFsidebaropen = false;
                                        self.togglePdfSideBar(PDFsidebaropen);
                                        self.acquiredImages.clear();
                                    }
                                    else {
                                        console.log(response);
                                    }
                                    // resolve();
                                });

                                break;
                            }
                    }
                }
                while (acquireModalState !== 0);
            }
            catch (ex) {
                alert('Catched error');
                alert(ex);
            }
            finally {
                if (twainDevice != null) {
                    // close the device
                    twainDevice.close();
                }
                resolve();
                // close the device manager
                self.twainDeviceManager.close();
            }
        });

    }
Could you help me?
Thank you.
Best Regards,
Luigi
Alex
Site Admin
Posts: 2305
Joined: Thu Jul 10, 2008 2:21 pm

Re: Which method to make the device asking for more document to scan?

Post by Alex »

Hi Luigi,

You have the problem because VintaSoft Web TWAIN service destroys/clears scanned images when TWAIN session is closed (TWAIN device manager is closed). Please close the TWAIN device manager only when scanned images are not necessary any more.

Best regards, Alexander
mywebforall
Posts: 15
Joined: Wed Mar 01, 2023 2:35 pm

Re: Which method to make the device asking for more document to scan?

Post by mywebforall »

Ok, thank you.

Best regards,
Luigi
Post Reply