Contact us

All times are UTC - 8 hours

   [ 2 posts ] 
Author Message

Joined: Mon Jul 03, 2017 11:37 am
Posts: 1
The online scan works fine with my scanner.

I have the need to get the scan as PDF/base64 image after scan, but when I check "HowManyImagesInBuffer" it is always 0.

<script type="text/javascript">
        function AcquireImage() {
            var DWObject = Dynamsoft.WebTwainEnv.GetWebTwain('dwtcontrolContainer'); // Get the Dynamic Web TWAIN object that is embeded in the div with id 'dwtcontrolContainer'.
            DWObject.IfDisableSourceAfterAcquire = true;    // Source will be closed automatically after acquisition.
            var bSelected = DWObject.SelectSource();                        // Select a Data Source (a device like scanner) from the Data Source Manager.
            var OnAcquireImageSuccess, OnAcquireImageFailure;
            OnAcquireImageFailure = function (){
            OnAcquireImageSuccess = function (){
                    DWObject.SelectedImagesCount = DWObject.HowManyImagesInBuffer;  //ALWAYS 0 ! !
                    for (var i = 0; i < DWObject.HowManyImagesInBuffer; i++) { // Loop through each of the images in the viewer.
                        DWObject.SetSelectedImageIndex(i, i);
                    //DWObject.SelectedImagesCount = 1;
                    //DWObject.SetSelectedImageIndex(0, 0);
                    var imagedata = DWObject.SaveSelectedImagesToBase64Binary();
                    var src = "data:image/png;base64," + imagedata;
            DWObject.OpenSource();                          // Open the source. You can set resolution, pixel type, etc. after this method. Please refer to the sample 'Scan' -> 'Custom Scan' for more info.
            DWObject.AcquireImage(OnAcquireImageSuccess, OnAcquireImageFailure);                        // Acquire image(s) from the Data Source. Please NOTE this is a asynchronous method. In other words, it doesn't wait for the Data Source to come back.
            // In order to do things during the scanning, you can use the events OnPostTransfer and OnPostAllTransfers. Please check out the sample UseEvent.html

User avatar

Joined: Tue Mar 08, 2005 12:23 am
Posts: 1706
Hi Arghargh,

Thanks for contacting Dynamsoft.

As you can see in the Remarks of AcquireImage, it's an asynchronous method. The callback functions are triggered as soon as the scan starts. Thus, the scanned images are not returned at that moment. My suggestion would be moving the successful callback part to OnPostAllTransfers event.

Please have a try and let me know how it works.


Dynamsoft Support Team
Follow us@Twitter, Facebook

Display posts from previous:  Sort by  
   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Copyright © 2018 Dynamsoft | All Rights Reserved
dynamic designed by Dynamsoft team
Fatal: Not able to open ./cache/data_global.php