Using active x and javascript to Scan From Your Web App

In the app I had been working on users had to perform a great amount of scanning. In the first few iterations this was done manually, which, of course, lead to lots of user error (namely scanning documents at high resolutions, which clogged the system). It was decided that it was best if our app to control the scan settings for most users. So we found three possible Active X controllers available to allow for this functionality. CianSoft, VintaSoft, and ChestySoft. After a little research we found that VintaSoft didn't quite meet our needs and that CianSoft's TwainX controller and ChestySoft's were eerily similar (it turns out that each company is run by a brother and both products were just different flavors of the same one). In the end ChestySoft was the one we went with because it allows you to perform posts of the scanned data to the server (and the guy that runs the company is super responsive when you have questions).

First there isn't too much to get this ActiveX controller up in running in the first place. There are great examples here that take you 95% of the way towards getting these up and running. A few little tricks we learned when setting up the javascript portion of the code are as follows:

  • To set the page size use the following method (the example sets it to letter):
csxi.SetTwainLayout(0,8.5,0,11)
  • Some scanners do not reset to their defaults after a custom scan. You need to make sure you manually set all default settings before scanning. A few you may want to set:
csxi.UseTwainInterface=false; //this makes sure that you are not prompted to change settings
      csxi.TwainAutoBright = true;
      csxi.TwainAutoDeskew = true;
  • When beginning a multipage scan you must run the following three methods:
csxi.TwainMultiImage = true;
      csxi.UseADF = true;
      csxi.ClearPDF();

One other fun thing we can do with ChestySoft's TwainX controller is upload the captured data directly to the server. To do this in the javascript you need to do the following:

Success = csxi.PostImage(url, file_name, param_name, graphics_format);
      if (Success) {
        //what to do when success
      } else {
        //what to do if error - here are recommendations:
        csxi.SaveToFile(path_on_desktop) //write data to desktop if you saved as a graphic;
        csxi.WritePDF(path_on_desktop) //write data to desktop if you saved as a pdf;
      }

Some notes about the preceding code. url a fully qualified url (including the 'http://'). file_name is what will be included as original_filename when you are reading data on the server side. graphics_format is a enumeration that can be found here.

And the best thing is after you click on the button that runs your scan the information uploaded is the same as a standard file upload so you don't have to do anything strange at all in ruby.

You've successfully subscribed to SmartLogic Blog
Great! Next, complete checkout for full access to SmartLogic Blog
Welcome back! You've successfully signed in.
Unable to sign you in. Please try again.
Success! Your account is fully activated, you now have access to all content.
Error! Stripe checkout failed.
Success! Your billing info is updated.
Error! Billing info update failed.