Java Scanning and Image Capture

High performance Java scanner access and imaging SDK for Windows 32bit/64bit and Mac OS X

Resources and FAQ's for Java Scanning SDK

    What about JTwain and JSane?

    We'll continue to offer JTwain and JSane. However, there are some limitations with both of them. JTwain can only runs on 32bit JVM. The main reason is most of vendors do not offer any 64bit TWAIN driver. This means even if JTwain is compiled into a 64bit library, no device will ever show up. Currently, you need JSane to access scanners on Linux and Unix operating systems.

    Java versions supported

    Java 1.6 is required. The SDK may work with Java version 1.4 and 1.5, however, these are not officially supported.

    Scan Programmatically

    The typical code flow: 1. Get the device and the functional unit; 2. Set the capabilities – color, bitdepth, paper size, etc; 3. Scan.

    List<Device> devices = ScanManager.getDefaultManager().getDevices(); // list all devices
    String deviceId = ScanManager.getDefaultManager().selectDeviceUsingUI(); // UI select
    Device device = Utils.searchDevice(devices, deviceId); // device object obtained
    FunctionalUnit flatbed = device.getFlatbed(); // each device may have multiple functional units
    FunctionalUnit feeder = device.getDocumentFeeder(); // could be null
    flatbed.setPixelDataType((FunctionalUnit.PixelDataType.COLOR); // set capabilities
    functionalUnit.scanOnePage(new File("test.jpg"), new ScanProgressListener() {
      public void started() {
        // progressBarScanPureJava.setValue(0);
      public void progress(final int percent) {
        // progressBarScanPureJava.setValue(percent);
      public void finished(String error) {
        // progressBarScanPureJava.setValue(100);
    }, null);

    Scan into memory

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    functionalUnit.scanOnePage(outputStream, null, null);
    System.out.println("Size of image scanned is: " + outputStream.size());
    byte[] bytes = outputStream.toByteArray();
    ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
    Image image =; // then you can display to UI

    Specify scan output format: TIFF, PDF, JPEG, PNG, etc

    output to PNG:

    functionalUnit.scanOnePage(outputStream, null, new FunctionalUnit.PropertyBuilder()

    Output to TIFF:

    functionalUnit.scanOnePage(outputStream, null, new FunctionalUnit.PropertyBuilder()

    Output to PDF:

    functionalUnit.scanOnePage(outputStream, null, new FunctionalUnit.PropertyBuilder()

    When file size is a concern, do use TIFF/PDF with CCITT Group 4 (T.6) to get ultra small size image files.

    Automatic Document Feeder (ADF) Scan

    Asprise Scanning and Image Capture SDK offers a clean and powerful API for ADF scan. Sample code:

    ScanManager manager = ScanManager.getDefaultManager();
    Device device = manager.getDevices().get(0);
    FunctionalUnit feeder = device.getDocumentFeeder();
    final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    fu.scan(new AbstractScanListener() {
      public Object getPageOutputTarget(int pageIndex, long pageId) {
        if(pageIndex <= 2) {
          return outputStream;
        } else { // accept max 3 pages (0, 1, 2).
          return 0;
     new FunctionalUnit.PropertyBuilder()

    The above code will scan max 3 pages and save the content in TIFF format into the memory. Note you use the getPageOutputTarget method to control output destination or to stop the scan by returning null. Besides streams, you can also return File.

    Back to top