I am trying to use a scanner with CmdTwain and Java to scan documents. The problem is that it does not always work. The other problem is that even with the installed drivers does not work on all computers, even if they all have the same OS, Windows 10. I do not know if there is any alternative to CmdTwain or there is anything that makes the scanner work only with Java.
This is the code I use to scan:
//HOOK para escanear la carpeta activamente sin cuadro de dialogo extra //SOLO PARA CEDULAS PARA EVITAR CODIGO ILEGIBLE
public void SCANNER() throws IOException
{
cargar = new Thread()
{
final String separador = File.separator;
final String current = new java.io.File(".").getCanonicalPath();
private void inicio()
{
String carax="nope";
String face="";
for(int x = 0; x < 2; x++)
{
if (x==0)
{
carax="FRONT";face="frontal";
}
else
{
if (x==1)
{
carax="BACK";face="trasera";
}
}
try
{
JOptionPane.showMessageDialog(null,"Ingrese la cara "+face+" en el escaner y presione OK.");
loadingced(true,"FRONT");
String ret="nope";
Path myDir = Paths.get(app.folder);
String archivo="";
try
{
Integer corre=1;
Integer front=0;
Integer back=0;
if (usatwain==true)
{
//JOptionPane.showMessageDialog(null, "Entré we");
String tmp=current + separador +"CmdTwain\Scanit.exe /DPI 300 /WH 2.125 3.370 scanner\DOC.jpg";
Process dunno= new ProcessBuilder(current + separador +"CmdTwain\Scanit.exe","/DPI", "300","/WH","2.125","3.370",current + separador +"scanner\DOC.jpg").start();
JOptionPane.showMessageDialog(null, tmp);
System.out.println(tmp);
}
while (corre==1)
{
WatchService watcher = myDir.getFileSystem().newWatchService();
myDir.register(watcher, StandardWatchEventKinds.ENTRY_CREATE,StandardWatchEventKinds.ENTRY_DELETE, StandardWatchEventKinds.ENTRY_MODIFY);
WatchKey watckKey = watcher.take();
List<WatchEvent<?>> events = watckKey.pollEvents();
//System.out.println(watckKey);
for (WatchEvent event : events)
{
if ((event.kind() == StandardWatchEventKinds.ENTRY_CREATE) || (event.kind() == StandardWatchEventKinds.ENTRY_MODIFY))
{
String exten = (event.context().toString()).substring((event.context().toString()).length() - 3);
if ("jpg".equals(exten))
{
//System.out.println("SI AL JPG");
archivo=(event.context().toString());
//System.out.println("LE DA AL ARCHIVO");
loadingced(false,"FRONT");
loading(true);
if (front==0)
{
front=1;
}
else
{
if (back==0)
{
back=1;
}
}
subir_fotocedula(archivo,carax);
//dunno.waitFor();
//System.out.println("SUBE FOTO");
loading(false);
//JOptionPane.showMessageDialog(null, "Imagen subida correctamente: ", "Subida correcta", JOptionPane.INFORMATION_MESSAGE);
ret="OK";
limpiarcedulas(carax);//Limpia todos los campos para evitar retencion de fotos
corre=0;
}
}
}
}
}
catch (Exception e)
{
System.out.println("Error: " + e.toString());
//JOptionPane.showMessageDialog(null, "El mero Error: " + e.toString());
}
if ("OK".equals(ret))
{
try
{
if ("FRONT".equals(carax))
{
cargarFotoCedulaFront(1);
}
if ("BACK".equals(carax))
{
cargarFotoCedulaBack(1);
}
}
catch (IOException ex)
{
Logger.getLogger(frmInicio.class.getName()).log(Level.SEVERE, null, ex);
}
}
} catch (Exception e)
{
MsgBox("Error: " + e);
}
}
}
@Override
public void run()
{
inicio();
}
};
cargar.start();
}