B4J Library [B4j] CmdTwain Wrapper

This is a B4xlib to control the free command line Twain Scanning app CmdTwain via jShell. (Windows Only)

It allows selecting a scanner and controlling scanning options, Partial page scanning is particularly useful. You can also select jpg, bmp or pdf outputs. Not all parameters are supported on all scanners. For instance, Black and White and Grayscale scanning is not supported on my Canon MG5750 All in one, but is supported on my older Epson V200. The CmdTwain help page is here.

Basic scanning is pretty simple, you just need to provide the path to the CmdTwain executable and an output file. It uses default parameters "PAPER A4 DPI 200 RGB" and they give you an A4 sized scan at 200 dots per inch in colour. You can override one or all of the default parameters,


Usage

Download and install the CmdTwain app from their main page.
Update the ST.ScanTwainPath call with your installation path if required (Default is "C:\Program Files (x86)\GssEziSoft\CmdTwain").
Update the ST.OutputFullPath with your target output file.

Comments

I haven't been able to test all of the parameters as my scanners do not have a document hopper, so I can't test anything to do with the document feeder.

I only need a simple scan so it serves my purposes well. There is now a simple Gui as a second b4xlib and a demo app - CmdTwainCV-b4xlib / CmdTwainCV-test

Demo
The attached file CmdTwain-test.zip contains a test project and requires the CmdTwain-b4xlib

Dependencies
CmdTwain app download
There are no external B4x Dependencies.

Enjoy, and please report any bugs.

Library Updates
V 0.11 - 11 Aug 2022
  • Tidied debug logging.
  • Changed Get/SetDPI to accept strings

New demo - 11 Aug 2022


Simple Gui Form and CustomView example as a separate b4xlib and demo app. CmdTwainCV-b4xlib / CmdTwainCV-test.​
Requires CmdTwain-b4xlib V 0.11+​
Demo update
V0.12 - 12 Aug 2022​
  • Tidied Debug logging
  • Renamed layout files to lowercase
  • Save Path to CmdTwain executable if changed
  • Added Custom dpi option and field
  • Added Scan EventListener(Start,Fail,Complete)
Download CmdTwainCV-b4xlib and CmdTwainCV-test.zip​
 

Attachments

  • CmdTwain-Test.zip
    2.4 KB · Views: 211
  • CmdTwain-b4xlib.b4xlib
    3.3 KB · Views: 199
  • CmdTwainCV-b4xlib.b4xlib
    7.2 KB · Views: 224
  • CmdTwainCV-test.zip
    2.2 KB · Views: 221
  • 1660299799995.png
    15.9 KB · Views: 177
Last edited:

stevel05

Expert
Licensed User
Longtime User
Update to V 0.11
  • Tidied debug logging.
  • Changed Get/SetDPI to accept strings

New demo
Simple Gui CustomView example as a separate b4xlib and demo app. CmdTwainCV-b4xlib / CmdTwainCV-test
 

Star-Dust

Expert
Licensed User
Longtime User
I have to say great. I have always appreciated your contributions which are always unique and open new paths.

A single note in the CmdTwainCV.test generates an error, certainly a distraction and a file is missing:
 

stevel05

Expert
Licensed User
Longtime User
Hmm, it was working in my test, but I did forget my golden rule. I usually make layout names in a b4xlib lowercase. it does seem to save problems like this.

Can you just try downloading the CmdTwainCV-b4xlib file again and try it.
 

Star-Dust

Expert
Licensed User
Longtime User
Hmm, it was working in my test, but I did forget my golden rule. I usually make layout names in a b4xlib lowercase. it does seem to save problems like this.

Can you just try downloading the CmdTwainCV-b4xlib file again and try it.
work fine
 

stevel05

Expert
Licensed User
Longtime User
Demo update
V0.12 - 12 Aug 2022
  • Tidied Debug logging
  • Renamed layout files to lowercase
  • Save Path to CmdTwain executable if changed
  • Added Custom dpi option and field
  • Added Scan EventListener(Start,Fail,Complete)

Download CmdTwainCV-b4xlib and CmdTwainCV-test.zip
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…