I am developing a desktop application in java to scan documents and save them in a database or directory, I use the WIA library (Windows Image Acquisition) and COM4J to use the objects of that library, I have managed everything except the scanning of the two sides of the sheet, the scanner that I have is a Canon DR-C225 .
According to Microsoft and Wiadef.h , the property for the double-sided scan is 3088 and it is assigned the value of 5 (Automatic Feeder + Double-sided Scanning) :
IDevice scanner = dialog.showSelectDevice(WiaDeviceType.ScannerDeviceType, false, true);
scanner.properties("3088").value(5);
The scanner tries to digitize the sheet, but an error arises (it arises for each sheet that is in the scanner) :
Error: com4j.ComException: 8000ffff Catastrophic failure: Catastrophic failure:. \ Invoke.cpp: 517 at com4j.Wrapper.invoke (Wrapper.java:166) at com.sun.proxy. $ Proxy12.transfer (Unknown Source)
In this line:
com4jObject = (Com4jObject) item.transfer(wiaFormatJPEG);
img = com4jObject.queryInterface(IImageFile.class);
When I use the WIA .exe (wiaacmgr.exe on System32), it scans both sides of the sheet without any problem.
Note: in the Stack Overflow forum in English I have also posted the question to see if they also help me there, so please, if someone knows about this issue, help me with this error, I would appreciate your help.
This is the complete code, when I scan a document on one side it scans perfect, but when I want to scan on both sides that error arises.
private final String wiaFormatJPEG = "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}";
public void acquireImage() {
try {
ICommonDialog dialog = ClassFactory.createCommonDialog();
IDevice scanner = dialog.showSelectDevice(WiaDeviceType.UnspecifiedDeviceType, false, true);
IItem item = scanner.items(1);
IImageFile img;
Com4jObject com4jObject;
//Pages to scan in each loop
scanner.properties("3096").value(1);
//Duplex property according Microsoft WIA and Wiadef.h
scanner.properties("3088").value(5);
//More properties (color, resolution, etc)
item.properties("6146").value(0);
item.properties("6147").value(300);
item.properties("6148").value(300);
item.properties("6151").value(300 * 8500 / 1000);
item.properties("6152").value(300 * 11000 / 1000);
int i = 0;
boolean hasMorePages = true;
while (hasMorePages) {
try {
//Create DeviceManager
IDeviceManager manager = ClassFactory.createDeviceManager();
for (Com4jObject comInfo : manager.deviceInfos()) {
IDeviceInfo info = comInfo.queryInterface(IDeviceInfo.class);
if (info.deviceID().equals(scanner.deviceID())) {
IProperties infoprop = null;
infoprop = info.properties();
//connect to scanner
scanner = info.connect();
break;
}
}
if (Integer.parseInt(scanner.properties("3087").value().toString()) != 0) {
//transfer the image
com4jObject = (Com4jObject) item.transfer(wiaFormatJPEG);
img = com4jObject.queryInterface(IImageFile.class);
//File to save the images
File file = new File(i + ".jpg");
if (file.exists()) {
//delete the image if exists
file.delete();
}
//Save the image
img.saveFile(file.getAbsolutePath());
//Read and write the image for reduce it weight
BufferedImage bi = ImageIO.read(file);
ImageIO.write(bi, "jpg", file);
}
} catch (Exception ex) {
.......Catch the errors
} finally {
//properties for document feeder scanner
IProperty documentHandlingSelect = null;
IProperty documentHandlingStatus = null;
for (Com4jObject comProp : scanner.properties()) {
IProperty property = comProp.queryInterface(IProperty.class);
if (property.propertyID() == 3088) {
documentHandlingSelect = property;
}
if (property.propertyID() == 3087) {
documentHandlingStatus = property;
}
}
hasMorePages = false; //assume that there are no more pages
if (documentHandlingSelect != null) //required for feeder but unsupported by flatbed
{
if (Integer.parseInt(documentHandlingSelect.value().toString()) != 0) {
hasMorePages = (Integer.parseInt(documentHandlingStatus.value().toString()) != 0);
}
}
i++;
}
}
} catch (ComException e) {
.........Catch the errors
}
}