Home › Forums › TWAIN Classic › From Java with user interface Twain
- This topic has 27 replies, 6 voices, and was last updated 8 years, 4 months ago by mikelilin.
- AuthorPosts
Hi!, I’m actually working with Java and I want to use Twain but I only want to scan from a scanner with a sets of parameters (Color, 300dpi). How can I do this without the user interfaze of Twain, only into a call to any function???. Thanks.
I am working on a similar project, so far I have determined that it is likely that we will have to go through JNI – Java Native Interface. Yesterday I found the header for twain as a consequence of looking in the driver forum here – I have managed to raise the scanner using Java Print API … took awhile and all I got was the printer name and a good listing of MIME types the printer can print. I also found some code on the Sun Fora which provides a remarkably good starting point.
License on the code is thus:
I know that it’s quite a long time that those posts are here but I found them while looking for an OCR solution in Java, and I would like to share the FREE answer I have created.
I browsed lots of posts while searching for OCR in Java, and all was linking to Asprise / javaocr, but those are unaffordable for non-commercial project.
URL == “http://forums.sun.com/thread.jspa?threadID=423280”
Java and OCR ( Ajit at York ) Started Jul 16, 2003 5:09 AM
Thank you very much. Now I have another problem. I want to scan in duplex mode and I don’t know how to capture the two images. Can you help me???.
I just gave up on using my new HP Officejet J4680 Series from shrink-wrapped software. Will be using hand-text_editor_manual method until such time as I can go through the headers for TWAIN. We must assume at this point that any such work will present unanticipated failures if we do not call,…..
Not intending to be difficult or make rebuttal, what is your question? That code I found gets bytes from an image file using established Java method calls, to do what I think you as will need be that we write the driver to talk to the device. That resolves to reading the headers for Twain. Have you read them? Basic idea is that is 2171 lines of defines, with two or three entry points for system calls so I need to ask what if any compiler are you using?
If you need to make a DLL to use TWAIN through JNI, the EZTwain classic library is a good start. We modified it to implement disk and buffered memory transfers and it saved us quite some time.
Also, duplex should be just setting CAP_DUPLEXENABLED and then scanning normally with no changes. You get the two sides as if they were different papers in single-side scanning.
Re-reading original poster’s question, I think I can ask this question: Where’s the rest of DS_Entry && DSM_Entry + thanks greatly for the steer on JNI but where is the cited tool? ( EZTwain classic library ) ( sources – compile from source ) … and while we’re at it, where are sources for Printer Control Language? Maybe I can just use twain.h but I don’t know what I’m doing here.
Finding the library is as easy as clicking the first result of searching for “eztwain classic” in google. The link to the zip with the sources is in that site.
As you can read in that page, it’s a “lite” version of the commercial product. So if you want more features you can either buy the commercial version or extend it yourself (which is what we did). The second option implies TWAIN knowledge, so reading the TWAIN spec is a must (the twain.h file is just the interface to twain, it doesn’t explain the internal design in depth).
About the printer, as far as I know TWAIN is designed for scanners, so you should look for a different tool to access the printer functions of the Officejet J4680.
Thanks to fct for recommending EZTwain! Here’s the home page of the free ‘Classic’ version:
http://www.dosadi.com/eztwain1.htm
The download includes the ready-to-run DLL, as well as C source code, and a Visual Studio 6 project to build it.We support a lot of languages with our commercial version of EZTwain, we’re beta-testing a Java wrapper. Instead of using JNI ourselves, we’re using a package called JNA that takes care of the JNI details for us:
https://jna.dev.java.net/Happy to chat with anybody interested in working with us on this, e-mail me as spike
dosadi com. @spike wrote:
Thanks to fct for recommending EZTwain!
No, thanks to you for offering the source. Getting the headache of a basic TWAIN implementation out allowed us to focus on scanner-specific features much earlier in the project.
spike, i’ll be talkin to ya – due to personal experience, i will be working from sources only, and for what it is worth – i use dm. ( google it ) I would have googled for EZ_Twain but sometimes such pages pop-up a rather infantile ui right in the browser client area and totally hook the kernel entry points to the point that one cannot regain a controlled shutdow-reboot with even crtl-alt-del so I just do not cook the info if i think it will lead to a commercial site. I enjoy digging into code, i wrote 1,800 lines of java in the past ten or so days from just before x-mas, fa8298b8 ampersand g *ail dot cee oh em.
my ask about PCL was to disentangle driving the printer from driving the scanner, it appears from doing a few scans since the post that driving the scanner portion of the hp may be done cleanly with twain.h
that is of course, after i find the implementation.
#ifdefined dewine
#define dewine declined
#else define dewine devinewouldn’t it be simpler just to do private static final String dewine =”devine”?
Hi Nicholas – If your browser lets a website “totally hook the kernel entry points to the point that one cannot regain a controlled shutdow-reboot with even crtl-alt-del”, I’d say you’re using the wrong browser!
So, you use… Depeche Mode? Decision Management tools? Decimeters? The TLD for Dominica? Data Mining? I feel I’m missing something…
i’ve seen those other tools, what they do for security doesn’t do anything for me, that is in large part why i want to do this scanner interface to java -all that stuff always shell-hookers everything … doing something like “shielding username from response header” or something, then it always calls into 16-code. Mozilla’s good, Firefox has some cool tools, what do you need them for?
I know it sounds off-topic, but that is exactly the topic. Ever read the headers for gc.h ?
Digital Mars, check it in to your code repository. Fast, single pass compiler with code path analysis.
if (TWAIN_Mgr(DG_CONTROL, DAT_IDENTITY, MSG_OPENDS, &twid))
and
if (OpenFile(szSMDir, &of, OF_EXIST) != -1) {
?? … so where’s …. this is gonna get involved, all this file read goes through some 16 bit legacy code that really should be fluffed to 1k buffers and burst-mode transfer in a wider data rate thinking, plus the device independent bitmap and making the data ( therein ) available to what Java calls a pixel grabber is going to be learning Data Source Manager … where’s the sources for that?
( I’m in over my head, I have never done graphics )
@Nicholas Jordan wrote:
plus the device independent bitmap and making the data ( therein ) available to what Java calls a pixel grabber is going to be learning Data Source Manager … where’s the sources for that?
( I’m in over my head, I have never done graphics )
You don’t need to send the in-memory DIB to Java. You can write it to a BMP file from C code (using the Windows API) and send the path(s) to Java. The TWAIN Data Source Manager is not involved in that part, you just quoted a function call that opens the device for scanning, and another (OpenFile) which is unrelated to TWAIN.
You can also implement different transfer modes (buffered, disk) that depending on the capabilities of the scanner will make the image available as already compressed JPGs, PNGs, TIFs, etc.
The TWAIN specs describe in depth how to implement those modes and the different image file formats that *might* be available on the scanner.
My extensions to the EZTWAIN classic library implement disk transfers to request data from the scanner to be saved directly to G4 compressed TIFs and JPEGs. Unfortunately my company doesn’t allow me to share code, but I can tell you that the implementation is short and mostly painless once you understand the concepts, as long as you’re comfortable with C/C++.
That was an exploratory work to open some headroom, I am swamped at the moment and have to patch up some work later in the datastream as I have concepting meeting this weekend, and – uh ….. Houston, … ? …. hello ?-! ( answer-back: ) “There are no problems, everyting is wonderful.”
That’s gonna get into SSL & PKI – running over absurdly mis-configured user-space. We ( my New Team Lead & I ) will be bringing up an Electronic Office, isolated from the paper office, good isolation subject to engineering grade work, review and testing. What my hope is here is that a scanner-driver, which may well and I expect it to, be callable through JNI – or any simple tool once I gain beginner grasp on the scope, nomenclature, and standard practices of the linkage issues …. surely we can pass a pointer to a few kilobytes or quarter meg or something, does not make sense to go through a context switch just to get 10-k of data.
Anyway: You have given me enough to work with now.
You can also implement different transfer modes (buffered, disk) that depending on the capabilities of the scanner will make the image available as already compressed JPGs, PNGs, TIFs, etc
I’m gonna model the entire project on HP Officejet J4680 Series, because I have one to do testing on, with the intent of making an efficient and safe driver across the entire HP small – mid size business products. With few hooks, a baseline or reference implementation upon which a coder, working in isolation and thwarted in attempts to get documentation can obtain enough info to get a functional and safe driver running, resistant to shell hooks.
I don’t want to scare people, obviously you are aware of the issues.
I’m gonna be swamped for a few days, I knew one call was a file creation call and the other was a minimal reference, what I need here is I have no familiarity with the codebase, so I do not know where to look for teh data trasfer modes that may have already been coded. It looks to me like it is what I think you are working arournd, a rather minimal implementation so if one wants to do graphics ( with the codebase ) then one will have to write some graphics.
The twist here is that I am experienced in this get-going phase, cannot resolve the above by looking at what I have unpacked.
EZTWAIN Classic (eztw32.dll) is a Windows DLL that provides an easy
interface to the TWAIN image acquisition protocol.Great, where’s the sources? I see:
Access
Clarion
Csharp
Dbase
Delphi
Lotusscript
Perl
Powerbasic
Powerbuilder
Progress
Vb
Vb.Net
Vc
Vfp
Readme.TxtTimeout, visit: The Boiler Room
I’ gonna have to do some preliminary orientation on:
saved directly to G4 compressed TIFs and JPEGs. Unfortunately my company doesn't allow me to share code, but I can tell you that the implementation is short and mostly painless once you understand the concepts, as long as you're comfortable with C/C++.
… to that end I am buried in Jeff Heaton’s Introduction to Neural Networks for Java right at the moment…….
What I am trying to do here is program away the “betrayal” that comes when someone who is not informed on computer science and does not wish to be tries to do intake on a thousand printed documents does not have to contort in fear of:
“… the crucial question is whether, on the information available to the defendant when the contract was made, he should, or the reasonable man in his position would, have realized that such loss was sufficiently likely to result from the breach of contract to make it proper to hold that the loss flowed naturally from the breach or that loss of that kind should have been within his contemplation.”
Source:Kuofos v. C. Czarikow Ltd. (The Heron II)
Contemporary shrink wrap insists on going through INT13, masking off needed control codes and data-blocking being done like a dime-size hole in the wall, rather than idempotence employed to gate system calls to the ideosyncratc scheduler of popular commercial grade software so as to get an efficient data-block size of say 100k or quarter meg or whatever it wants so that it is the 802.11-G that is throttlling, not the device or the mainboard and process asscociated with intake.
I can spec some stuff here, now, and in perpituity: We take a raw image stream, do AI on it ( as OCR ) and take what can be recognized as a base character set ( okay, internationalization is here – still, we work to the benefit of technical people ) leaving styled document, as though it were never here, never discussed, only twiddly-diddly for people who want to be nice.
At some point, shortly there after, we proide what in computer science is called a filter interface, such that human intervention either by gui or by spell checker and context validation, is provided for the the programmer and Team Lead. It is part of the license that the code cannot be used save user accept the burden to implement some sort of sanity check at this point.
Then we give a text stream in Java, as Java’s Great Bean directs, free of system-dependent issues such as 0X0A / 0X0D letting 0xcafebabe rule from thereon……
Consider taking your next vacation in the Chinggis khaan home land.
- AuthorPosts