1

I am developing a java application that can search my system and find all the scanners and lets me select if there are more than one scanner installed and proceed for scanning the document. I understand i should use twain for this. I have a library file in my system path but i have no idea how do i use this. Are there any sample programs on how to use this in my java application.

I have found the below sample code that uses WIA for communicating with the scanners. Is there any jar file to import to my netbeans or is there any other way out.

WIA.DeviceManager manager = new WIA.DeviceManagerClass();
string deviceName = "";
foreach (WIA.DeviceInfo info in manager.DeviceInfos)
{
    if (info.Type == WIA.WiaDeviceType.ScannerDeviceType)
    {
        foreach (WIA.Property p in info.Properties)
        {
            if (p.Name == "Name")
                {
                    deviceName = ((WIA.IProperty)p).get_Value().ToString();
                    Console.WriteLine(deviceName);
                }
        }
    }
}

3 Answers3

2

I'm not sure what library you're using, but I'd recommend one of these two:

Morena (low price, good documentation and email correspondence):

http://www.gnome.sk/index.html

mm's computing (open-source LGPL)

http://thorntonzone.com/manuals/Compression/Fax,%20IBM%20MMR/MMSC/mmsc/uk/co/mmscomputing/device/twain/index.html

If you're willing to pay a small price I'd recommend Morena. With Morena 6 (TWAIN) I was able to make a scan applet (called externally) that returns base64 jpeg data, and only ended up with 145 lines of my own Java code. On top of that they have full working examples and a very good FAQ page that covered almost every error I encountered. I haven't played with mms computing's plugin much because I didn't find out about it until after the Morena project was done.

MaKR
  • 1,882
  • 2
  • 17
  • 29
1

It is really difficult for someone to make such decisions without knowing a lot about what we are dealing with. First let me shed some light on it.

Every Scanner device comes with a custom scan driver. These drivers either use TWAIN or WIA for communicating with the applications that use the drivers. In other words for all the applications that use these drivers there are two protocols that has to be followed: WIA : https://msdn.microsoft.com/en-us/library/windows/desktop/ms630368(v=vs.85).aspx

TWAIN: http://www.twain.org/

Trust me you do not want to get in to the details of these.

So your goal would be to use on one of the protocols in your application to query the devices. The code bit you have pasted is a WIA c# sample app that queries and lists all the WIA only drivers installed on the machine.

I would really suggest you to use TWAIN as WIA is completely based on COM and for someone outside C++ world its quite difficult and also I'm not sure if WIA protocol supports TWAIN but the other way round is suppose to work.

If I were to do something like you I would consider writing a custom wrapper for TWAIN in Java like a interop in C# world. TWAIN is supposed to be easier compared to WIA.

In case of any confirmation required feel free to ask.

Thanks!

0

It's C# code. To make JVM and CLR work together, you can use jni4net to wrap the code block. You can read the article Java TWAIN with Dynamic .NET TWAIN and jni4net to learn how to call .NET code in Java.

yushulx
  • 11,695
  • 8
  • 37
  • 64