Batch Scanning

 

If the scanner has an ADF (automatic document feeder) you can use software batch scanning. In this case you can scan papers to single pages or to multipage TIFF files. You can choose the compression of the file before scanning using the SetBatchScanImageCompression function/method. In this case, the scanner generates a DIB in memory and the BiTwain saves the DIB to the disk as a TIFF file.

If the scanner is a high speed scanner with an ADF use the hardware batch scanning. In this case the scanner generates files according to the ICAP_IMAGEFILEFORMAT. If the image file format is a single page format, the files will be indexed (for example test00001.bmp, test00002.bmp etc). If the file format is multipage, such as TIFF, the scanner acquires pages to a multipage TIFF file.

 

Before batch scanning you should specify some capabilities:

 

  1. Enable the feeder so that the scanner will scan from the feeder. (SetFeederEnable)

  2. Set ICAP_AUTOFEED. The TWAIN source will automatically feed the next page from the document feeder.

  3. Set the number of pages to scan.

 

[C++]

 

/* Batch Scanning */

 

#include “BiTwain.h”

 

// Set CAP_FEEDERENABLED

CListBox* pMsgBox = (CListBox*)GetDlgItem(IDC_LIST);

char szTemp[32];

char szError[128], szMsg[128];

DWORD dwNeeded;

 

int err = GetFeederEnabled(&iEnabled);

if (err != TW_OK)

{

            GetErrorString(err, szError, 128, &dwNeeded);

            sprintf(szMsg, "Getting current value of

CAP_FEEDERENABLED failed. Error: %s", szError);

            pMsgBox->AddString(szMsg);

            return;

}

 

if (!iEnabled)

{

            err = SetFeederEnable(TRUE);

 

            if (err != TW_OK)

            {

                        GetErrorString(err, szError, 128, &dwNeeded);

                        sprintf(szMsg, "Setting current value of

CAP_FEEDERENABLED failed. Error: %s", szError);

                        pMsgBox->AddString(szMsg);

                        return;

            }

}

 

// Set CAP_AUTOFEED

DWORD dwReturned;

LPSTR szValue = NULL;

 

err = GetCapabilityOneValue(CAP_AUTOFEED, MSG_GETCURRENT,

NULL, 0, &dwNeeded, &dwReturned);

 

if (dwNeeded > 0)

{

            szValue = (LPSTR)calloc(dwNeeded, sizeof(char));

            if (szValue)

            {

                        err = GetCapabilityOneValue(CAP_AUTOFEED,

MSG_GETCURRENT, szValue, dwNeeded, &dwNeeded,

&dwReturned);

 

                        if (err == TW_OK)

                                    iEnabled = atoi(szValue);

                        else

                        {

                                    GetErrorString(err, szError, 128,

&dwNeeded);

                                    sprintf(szMsg, "Getting current value of

CAP_AUTOFEED failed. Error: %s", szError);

                                    pMsgBox->AddString(szMsg);

                        }

 

                        free(szValue);

            }

            else

            {

                        pMsgBox->AddString("Memory allocation error");

            }

 

}

else

{

            GetErrorString(err, szError, 128, &dwNeeded);

            sprintf(szMsg, "Getting current value of CAP_AUTOFEED

failed. Error: %s", szError);

            pMsgBox->AddString(szMsg);

}         

 

if (!iEnabled)

{

            err = SetCapabilityOneNumValue(CAP_AUTOFEED, MSG_SET,

TRUE);

 

            if (err != TW_OK)

            {

                        pMsgBox->AddString("Unable to set CAP_AUTOFEED

capability");

                        return;

            }

}

 

err = IsFeederLoaded(&iEnabled);

 

if (err == TW_OK)

{

            if (!iEnabled)

            {

                        pMsgBox->AddString("Feeder is empty.");

                        pMsgBox->SetTopIndex(pMsgBox->GetCount()-2);

                        return;

            }

}

else

{

            GetErrorString(err, szError, 128, &dwNeeded);

            sprintf(szMsg, "Getting current value of

CAP_FEEDERLOADED failed. Error: %s", szError);

            pMsgBox->AddString(szMsg);

            return;

}

 

/* Software batch scanning */

SetBatchScanImageCompression((int)TCOMP_NOCOMP);

BatchScan(“C:\\Images\\Test.tif”, TRUE, 3);

 

[VB]

 

Batch Scanning

 

Dim bEnable As Boolean

Dim err As Long

Dim szData As String

   

' Try to set Bacth Scan Capabilities

bEnable = BiTwain.GetFeederEnabled

   

If BiTwain.ErrorCode <> TW_OK Then

     LBLIST.AddItem ("Getting current value of _

     CAP_FEEDERENABLED failed. Error: ") + _

     BiTwain.GetErrorString _

(BiTwain.ErrorCode)

     LBLIST.ListIndex = LBLIST.NewIndex

     Exit Sub

End If

   

If bEnable = False Then

     err = BiTwain.SetFeederEnable(True)

       

     If err <> TW_OK Then

        LBLIST.AddItem ("Setting current value of _

   CAP_FEEDERENABLED failed. Error: ") + _

   BiTwain.GetErrorString _

   (BiTwain.ErrorCode)

        LBLIST.ListIndex = LBLIST.NewIndex

        Exit Sub

     End If

End If

   

' Set CAP_AUTOFEED

szData = _

BiTwain.GetCapabilityOneValue(CAP_AUTOFEED, _

MSG_GETCURRENT)

If BiTwain.ErrorCode <> TW_OK Then

   LBLIST.AddItem ("Getting current value of CAP_AUTOFEED _

   failed. Error: ") + _

   BiTwain.GetErrorString _

   (BiTwain.ErrorCode)

   LBLIST.ListIndex = LBLIST.NewIndex

   Exit Sub

End If

   

If CLng(szData) = 0 Then

    err = _

BiTwain.SetCapabilityOneNumValue(CAP_AUTOFEED, _

MSG_SET, 1#)

      

    If err <> TW_OK Then

        LBLIST.AddItem ("Setting current value of _

   CAP_AUTOFEED failed. Error: ") + _

   BiTwain.GetErrorString _

   (BiTwain.ErrorCode)

        LBLIST.ListIndex = LBLIST.NewIndex

        Exit Sub

    End If

End If

   

' Verify feeder loaded

If BiTwain.IsFeederLoaded = False Then

    LBLIST.AddItem ("Feeder is empty")

    LBLIST.ListIndex = LBLIST.NewIndex

    Exit Sub

End If

 

‘ Software batch scanning

 

BiTwain.SetBatchScanImageCompression 201 ‘ TCOMP_NOCOMP

BiTwain.FileAcquire = “C:\Images\Test.tif”

BiTwain.BatchScanImageCount = 3

BiTwain.MultiPage = True

BiTwain.Action = TWSTAT_BATCHSCAN

 

[C#]

 

/* Batch Scanning */

 

int err;

string szData;

bool bEnable;

 

// Try to set Bacth Scan Capabilities

bEnable = BiTwain.GetFeederEnabled();

                                   

if (BiTwain.ErrorCode !=

(int)BITWAINLib.enumErrorCodes.TW_OK)

{

            LBLIST.Items.Add("Getting current value of

CAP_FEEDERENABLED failed. Error: " +

BiTwain.GetErrorString(BiTwain.ErrorCode));

            return;

}

 

if (!bEnable)

{

            err = BiTwain.SetFeederEnable(true);

 

            if (err != (int)BITWAINLib.enumErrorCodes.TW_OK)

            {

                        LBLIST.Items.Add("Setting current value of

CAP_FEEDERENABLED failed. Error: " +

BiTwain.GetErrorString(BiTwain.ErrorCode));

                        return;

            }

}

 

// Set CAP_AUTOFEED

szData = BiTwain.GetCapabilityOneValue

((int)BITWAINLib.enumCapabilities.CAP_AUTOFEED, (int)BITWAINLib.enumCapabilityOperations.MSG_GETCURRENT);

                                   

if (BiTwain.ErrorCode !=

(int)BITWAINLib.enumErrorCodes.TW_OK)

{

            LBLIST.Items.Add("Getting current value of

CAP_AUTOFEED failed. Error: " +

BiTwain.GetErrorString(BiTwain.ErrorCode));

            return;

}

 

if (Convert.ToInt32(szData) == 0)

{

            err = BiTwain.SetCapabilityOneNumValue

((int)BITWAINLib.enumCapabilities.CAP_AUTOFEED, (int)BITWAINLib.enumCapabilityOperations.MSG_SET, (float)1.0);

 

if (err != (int)BITWAINLib.enumErrorCodes.TW_OK)

{

                        LBLIST.Items.Add("Setting current value of

CAP_AUTOFEED failed. Error: " +

BiTwain.GetErrorString(BiTwain.ErrorCode));

                        return;

}

 

}

 

// Verify feeder loaded

if (BiTwain.IsFeederLoaded() == false)

{

            LBLIST.Items.Add("Feeder is empty" +

BiTwain.GetErrorString(BiTwain.ErrorCode));

            return;

}

 

/* Software batch scanning */

 

BiTwain.SetBatchScanImageCompression(201); // TCOMP_NOCOMP

BiTwain.BatchScanImageCount = 3;

BiTwain.FileAcquire = “C:\\Images\\Test.tif”;

BiTwain.MultiPage = true;

BiTwain.Action = (short)BITWAINLib.enumScanOperations.TWSTAT_BATCHSCAN;