Scanning from the ADF using WIA in C#

Updated on Wednesday, June 2, 2021

Scanner ready for WIA image acquisition

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

Updates

Catfood: PdfScan 1.40

Catfood: PdfScan 1.40

Catfood PdfScan 1.40 is a small bug fix release. PdfScan converts documents to PDFs with the help of a flatbed or automatic document feeder (ADF) scanner.

Scanning multiple pages into a PDF file

PdfScan is a simple tool for scanning pages into a PDF file. You can scan single pages from a flatbed scanner or several pages from a document feeder. The page size applies to both the scan and the page(s) added to the PDF.

I wrote PdfScan because I know I'm going to be scanning a lot of documents over the next couple of weeks. Previously I used a tool called ScanToPDF from O Imaging but their licensing pissed me off so much that I'd rather waste time reinventing the wheel than pay them for another copy.

PdfScan - Scan pages to a PDF

This is a beta — it works with my scanner and my documents. There's no installer, so extract the ZIP file and run the EXE to use it. PdfScan requires the .NET 4.0 Framework. If you get an error when you run PdfScan.exe try installing .NET 4 and then run it again.

If enough people use this I'll make it a bit more friendly, add an installer and release it through Catfood. If you like it leave a comment below. If it doesn't work for you leave a comment or email me and I'll try to help.

(Update September 12, 2010: I've tided PdfScan up and released it through Catfood Software. Download from Catfood PdfScan.)

PdfScan uses PDFsharp from empira Software. Thanks chaps!

Add your comment...

Related Posts

You Might Also Like

(All Code Posts)

(Published to the Fediverse as: Scanning from the ADF using WIA in C# #code #pdf #scanning #wia #pdfscan #scan #scanner #scantopdf How to make a scanner use the document feeder (ADF) rather than the flatbed using WIA from C#. )

Comments

Robert Ellison

You can grab it from the downloads page here, or from GitHub.

Ayad A Jaleel

Kindly we need PdfScan for scanning documents to PDF

Juan Francisco Binaghi
I have a similar problem: need a method to get the multiples images obtained from a EPSON GT-S80 scanner. Always throws me the error 0x80210003. you could guide me to fix my method?
Rob Ellison

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?

ameerasajid

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?

Rob Ellison

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).

romrom

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.   

David Wetherell

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 ...

Jonaze

I found a solution, set the property "3096" (Pages) to 1

Jonaze

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.

Add Comment

All comments are moderated. Your email address is used to display a Gravatar and optionally for notification of new comments and to sign up for the newsletter.

Newsletter

Related

Catfood Software Support