HOWTO: Scan pages from a document feeder to a multipage TIFF


In order to scan multiple images from a document feeder into a multipage TIFF, you need to use the Acquire method and handle the ImageAcquired, AcquireFinished and optionally AcquireCanceled events.

Here is the basic code. It assumes an Acquisition object named twain, a WorkspaceViewer named viewer and a bool variable named acquireCanceled is present.

[C#]

private void ScanToMultiTiff()
{
    this.acquireCanceled = false;
    this.twain.ShowSelectSource();
    this.twain.Acquire();
}
  
private void OnImageAcquired(object sender, AcquireEventArgs e)
{
    if (e.Image != null)
    {
		this.viewer.Images.Add(AtalaImage.FromBitmap(e.Image));
	}
}
  
private void OnAcquireCanceled(object sender, EventArgs e)
{
     this.acquireCanceled = true;
}
  
private void OnAcquireFinished(object sender, EventArgs e)
{
    if (!this.acquireCanceled)
    {
        this.viewer.Save(@"C:\multi.tif", new TiffEncoder(TiffCompression.Group4FaxEncoding));
    }
}

[Visual Basic]

Private  Sub ScanToMultiTiff()
    Me.acquireCanceled = False
    Me.acquisition.ShowSelectSource()
    Me.acquisition.Acquire()
End Sub
 
Private  Sub OnImageAcquired(ByVal sender As Object, ByVal e As AcquireEventArgs) Handles twain.ImageAcquired
    If Not e.Image Is Nothing Then
       Me.viewer.Images.Add(AtalaImage.FromBitmap(e.Image))
    End If
End Sub
 
Private  Sub OnAcquireCanceled(ByVal sender As Object, ByVal e As EventArgs) Handles twain.AcquireCanceled
     Me.acquireCanceled = True
End Sub
 
Private  Sub OnAcquireFinished(ByVal sender As Object, ByVal e As EventArgs) Handles twain.AcquireFinished
    If Not Me.acquireCanceled Then
        Me.viewer.Save("C:\multi.tif",New TiffEncoder(TiffCompression.Group4FaxEncoding))
    End If
End Sub

Original Article:

Q10040 - HOWTO: Scan pages from a document feeder to a multipage TIFF