7

I am trying to scan a few pages from the feeder, although the scanner automatically scans all the pages when I call ShowTransfer function (without using a loop), I am getting back only the first page.

what am I doing wrong?

here's my code:

  WIA.Item item = device.Items[1] as WIA.Item;

            if (pages > 1)
            {
                // Set to feeder
                SetWIAProperty(device.Properties, 44, 1);
            }

            SetWIAProperty(device.Properties, WIA_DEVICE_PROPERTY_PAGES_ID, 1);

            AdjustScannerSettings(item, 150, 0, 0, 1250, 1700, 0, 0, 1);
            try
            {

                // scan image
                WIA.ICommonDialog wiaCommonDialog = new WIA.CommonDialog();
                WIA.ImageFile image = (WIA.ImageFile)wiaCommonDialog.ShowTransfer(item, wiaFormatBMP, false);

                // save to temp file
                string fileName = Path.GetTempFileName();
                File.Delete(fileName);
                image.SaveFile(fileName);
                image = null;
                // add file to output list
                images.Add(Image.FromFile(fileName));
            }
            catch (Exception exc)
            {
                throw exc;
            }
mendy
  • 127
  • 1
  • 9

1 Answers1

3

I think this link is doing what you want to do

http://forums.codeguru.com/showthread.php?439027-Windows-Image-Acquisition-(WIA)-Code

Basically, you need to check after saving off each page to see if there are more pages and keep looping

                hasMorePages = false; //assume there are no more pages
                if (documentHandlingSelect != null)
                    //may not exist on flatbed scanner but required for feeder
                {
                    //check for document feeder
                    if ((Convert.ToUInt32(documentHandlingSelect.get_Value()) & WIA_DPS_DOCUMENT_HANDLING_SELECT.FEEDER) != 0)
                    {
                        hasMorePages = ((Convert.ToUInt32(documentHandlingStatus.get_Value()) & WIA_DPS_DOCUMENT_HANDLING_STATUS.FEED_READY) != 0);
                    }
                }
justjoshin
  • 114
  • 6
  • When the line of ShowTransfer() get Executed, the scanner scan all the pages, So if I'll implement a loop - at its second iteration it would throw an exception (the feeder is empty). If there is a way to force the scanner to scan only one page for ShowTransfer() call, I could use this code. – mendy Feb 27 '20 at 08:08
  • 1
    Take a look at [this question](https://stackoverflow.com/questions/30743888/wia-2-0-duplex-scanning) - if I'm not mistaken it has the solution to scan one page at a time. – Grx70 Mar 02 '20 at 21:15
  • 1
    Also, it looks like if you called `ShowTransfer` again it would pull the next page from the device memory rather than initiate new scan (although I might be wrong). As a side note, I recall something about having to set `Item` properties first, and only then `Device` properties, otherwise it does not work. But I can't find any reference to that information at the moment. – Grx70 Mar 02 '20 at 21:21
  • 2
    [Found it](https://ithoughthecamewithyou.com/post/scanning-from-the-adf-using-wia-in-c). "After much experimentation I discovered a solution. I had been setting device properties and then setting item properties before requesting the scan. Switching the order - item then device - made everything work." – Grx70 Mar 02 '20 at 21:24