Monday, March 21, 2011

Trigger a Scanner using a button in InfoPath form - C#

As I have mentioned in one of my previous post I was spending some quality time with a scanning requirement. Requirement is simple, which is in a SharePoint form there should be separate buttons for scanning multiple documents. There are a lot of plugins  for SharePoint that can trigger a scanner and the most funniest thing is they only provides a limited functionality. And that is, first we should insert a item and then select the item and do the scanning. We can scan multiple documents and the same time it attaches them to the item. (people who might not familiar with SharePoint, might not understand what i told above about the scanning plugins for SharePoint).

But my requirement was not that. The form should have multiple buttons for trigger the scanner. Finally I planned to do some programming with InfoPath and somehow getting my thing done. Finally I have managed to develop multiple buttons to do multiple scanning and attaching to the same document same time, but of course it has some boundaries. I will explain the boundaries later in my post.

I have used Windows Image Acquisition Library 2.0 which can be downloaded for free from Microsoft. It has nice capabilities as well as some limitations. The one of the main limitations is Windows Image Acquisition Library is used for mainly capturing images from imaging devices such as scanners and cameras. So from what I have done, i was only able to get the output of the scanned documents as image type outputs such as JPEG, PNG etc. And the other main limitation is, it does not provide multi page scanning and the reason behind that is again WIA is used for mainly capturing images.

If I talk about the main boundaries of my scanning requirement development, first one is InfoPath form should be uploaded as a form template and should be set to open in the Client Application. The reason for this is if we enabled the InfoPath form to open in the browser, that means the InfoPath form is running on the Server. But the Client machine does not allow the Server to communicate with the Client machine's ports which simply means we cant trigger the scanner. So the InfoPath form should be opened in the Client machine. The other boundary is with the WIA, which is what I have explained above.

I am thinking and doing some things to overcome these boundaries. My solution for communicating with the Client machine from the Server is developing a service or a Client application which is fully separated from the Server and forget about the InfoPath form. Then design a form as a Visual Web Part using Visual Studio and deploy it to the Server. And then using a javascript or a vbscript, trying to communicate with the service or the Client Application, which is so far some what successful.

And for the second boundary, still I have not tried anything. I thing for that either I will have to convert JPEG/PNG into PDF file and add the functionality to add multiple pages to a single document, which seems pretty hard. So I think I might have to change my track into TWAIN scanning.

Will update all of you as soon as I have manage to overcome these boundaries. But I am fully happy with what I have done, because I am not using any of the plugins which you will have to buy to use it.

Happy Coding.

Regards,
Jaliya