I've been going nuts trying to scan from the document feeder on my Canon imageClass MF4150. Everything worked as expected from the flatbed, no dice trying to persuade the ADF to kick in. I found some sample code but it was oriented towards devices that can detect when a document is available in the feeder. Evidently my Canon doesn't expose this and so needs to be told the source to use.
The way to do this is to set the WIA_DPS_DOCUMENT_HANDLING_SELECT property to FEEDER. You then read WIA_DPS_DOCUMENT_HANDLING_STATUS to check that it's in the right mode and initiate the scan. This did not work for toffee.
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.
Here's the function to scan one page:
A few notes — XImage is a type from PDFSharp. I wrote this as part of a PDF scanner that I'll post next so the scanned images are saved and then loaded into an XImage for rendering to the PDF document. The magic numbers come from WiaDef.h in the Platform SDK. If the ADF is out of pages this method sets the return image to null and eats the exception. This is because the function is called repeatedly to scan in pages until the ADF is empty if _adf is true (otherwise it grabs one image from the flatbed).
If you've been banging your head against a wall trying to get WIA to work with a document feeder I hope this helps.
Updated 2015-05-20: Full source code at https://github.com/abfo/pdfscan
Can you post the full code? I can't resolve SetItemIntProperty or SetDeviceIntProperty.
Here are the methods to drop in:
(grin) Thanks Rob. I've been reading a bunch about WIA the last couple days and I just went ahead and implemented those yesterday afternoon as Extension methods on the Properties object and also another helpful one on the COMException object. Check 'em out:
Hugh - very nice! Thanks for sharing that.
How do you determine the value of the "_adf" variable? I need to detect if the scanner has a flatbed, but I can't figure out how to do it.
Aurelio, _adf in the above snippet is set by the use - true to use the feeder, false to use the flat bed. It then sets the appropriate mode.
To see if the scanner has a flat bed check the WIA_DPS_DOCUMENT_HANDLING_CAPABILITIES property (http://msdn.microsoft.com/en-u....
Sorry bad link, try: http://msdn.microsoft.com/en-u...
Thanks a lot Rob!
This code doesn't work for me. It stalls after checking the handling status. It acts like it is not setting the device handling to the feeder. Is there an issue with specific devices not being able to be set from WIA?
No exception? It just hangs?
I know that some devices can detect if a document is in the ADF in which case you might not need to set the ADF option before scanning. If you comment this out does it get any further?
It throws an exception that the value is not in range when the ShowTransfer method is called. If I comment out trying to change the prop, it automatically selects the flatbed.
I took out the check for status and it throws a value out of expected range exception when it calls ShowTransfer. If I don't try to set the prop, it automatically goes to the flatbed. This is driving me insane.
What is the device that you're trying to work with? Have you tried checking to see if you have the latest drivers installed?
Brother MFC-7340. I uninstalled and reinstsalled the device, double checked that the drivers were accurately installed and I get the same results.
What is reported for the WIA_DPS_DOCUMENT_HANDLING_CAPABILITIES property (see comments above with MSDN link)?
It comes back as 3. I'm not certain which constant that is. I am on Win 7 64bit.
Sorry - need to fix these nested comments, getting a bit narrow down here.
'3' is FEED and FLAT, so no auto-detection capability. You can get the constant values from WiaDef.h (in the Platform SDK).
I'm out of ideas for now. I'll post back if I think of anything else. Please let me know if you figure this out so I can update the sample code if necessary.
I have exactly the same problem with a Brother 6490, property 3087 always return "3". I have found the following explanation on msdn : http://msdn.microsoft.com/en-u....
But I don't found any solution to use the feeder. Normally it is the device which must select the ADF automatically.
I found a solution, set the property "3096" (Pages) to 1
Great post ... I looked all over the place for a decent WIA example example and was about to give up when I uncovered this ! I was amazed that everything was pointing to a 10 yr article on codeproject for some crap twain example. I'm gonna post this link to some of the threads on stack overflow, hopefully will save some people some time ... Thank you, much ...
Looks good, but when I ran it with an HP OfficeJet Pro 8500A Plus, the ADF pulled two pages (instead of one), but the code only spit out a single JPG.
Did you get a device progress dialog, and did this appear once or twice? Are the DPI/Width/Height set correctly for the paper type that you're scanning? Not sure what else to suggest other than maybe checking to see if updated firmware or drivers exist for your device (could be a device bug).
My application works well with HP printers (HP Scanjet 7650 and HP officejet Pro L7780) but it doesnt work with brothersoft 9460cdn. Any idea what issue it could be?
Do you know where it's failing? Any exception or error code? Hard to troubleshoot without a specific issue. There are a few earlier posts about a Brother device in the thread, could it be the same issue?