Example 14: Job and Batch Processnig |
Top Previous Next |
Example: Acquire images using device that supports job control and batch processing.
#include "cdtwain.h" // CDTwain #include <iostream> #include <algorithm> // for std::find
using namespace DTWAIN; using namespace std; // for <iostream>
int main( ) { // Initialize DTWAIN - return if initialization does not work DTwainInterface TI; if ( !TI.IsValid( ) ) return 0;
// Declare a Source and assign the TWAIN source to it DTwainSource Source = DTwainSource::Select( ); if ( !Source.IsValid( ) ) return 0;
if ( !Source.IsJobControlSupported( ) ) { cout << "Device does not support job control. Exiting"; return 0; }
// get all of the supported job control types DTwainLongArray AllJobControls; Source.EnumJobControls( AllJobControls );
// we would like to exclude the job separator page when scanning. Check if it's in the list of supported types if ( find(AllJobControls.begin( ), AllJobControls.end( ), DTWAIN_JC_JSXC ) != AllJobControls.end( ) ) Source.SetJobControl( DTWAIN_JC_JSXC ); else // include the job separator page. if ( find(AllJobControls.begin( ), AllJobControls.end( ), DTWAIN_JC_JSXC ) != AllJobControls.end( ) ) Source.SetJobControl( DTWAIN_JC_JSIC ); else { cout << "Could not find appropriate job control type"; return 0; }
// Acquire to a multipage Group 4 TIFF file. Base file name is JOB0000 DTwainAcquirer Acquirer(Source); Acquirer.SetFileNumberIncrement( 1 ). // auto increment the number field in the base file name. SetUIMode( false ). // no user interface SetMultiPageFileMode( ). // scan to a multipage file, not individual files SetColorType(COLORTYPE_BW). // make sure pixel level is 1-bit (black/white) for group 4 TIFF files. EnableFeeder( true ). // enable the document feeder Acquire("JOB0000.TIF", FILETYPE_TIFFG4); // start the acquisition }
The code above will create multipage Group4-TIFF files called JOB0000.TIF, JOB0001.TIF, JOB0002.TIF, etc. that will contain the pages of each batch job that was acquired. The separator page determines the start of a new job. Note that the device must support job/batch processing using TWAIN. |