C#: Online Guide
How To: Twain SDK
Scan Multi-pages into One PDF Document
Scan Multi-pages into One PDF Document
Home ›› XImage.Twain ›› C# Twain: Scan Multi-pages into One PDF Document

C# TWAIN - Acquire or Save Image to File

How to Save Acquired Image to File in C#.NET with TWAIN Add-on

Overview - Save Image to File with C# TWAIN Device

RasterEdge C#.NET TWAIN Add-On enables developers to directly acquire image to file with a couple of code lines in C# programming project. Using this C#.NET TWAIN Add-On, you are capable of scanning images from digital imaging devices (such as TWAIN compatible scanners and digital cameras) automatically and saving the images to file in C#.NET application.

Related .net document control helps:
asp.net powerpoint document viewer: ASP.NET PowerPoint Document Viewer Control: view pptx files online in C# using ASP.NET
asp.net pdf file permission: ASP.NET PDF File Permission Control: apply, remove PDF file permission settings in C#
asp.net convert pdf: ASP.NET Convert PDF Control: Convert, export PDF to Word, HTML, Tiff files in C# ASP.NET
asp.net redact pdf: ASP.NET Redact PDF Document Control: redact, remove PDF text, images in web browser using C# ASP.NET
asp.net mvc document viewer: ASP.NET MVC Document Viewer: view, annotate, redact files on ASP.NET MVC web projects
asp.net dnn document viewer: DNN Document Viewer Control: view, annotate, redact, convert documents in dotnetnuke ASP.NET
asp.net sharepoint document viewer: ASP.NET SharePoint Document Viewer: view, annotate, redact documents in SharePoint

If you want to acquire an image directly into the C#.NET application in which you are going to work with the image, you'd better use the widely used application programming interface - TWAIN. TWAIN is not a hardware-level protocol, but a communication protocol that realizes connection between software and digital imaging devices. Our C#.NET TWAIN Add-On supports acquiring or saving image to file by using compression algorithm supported by the device.

C# TWAIN Scanning DLLs: Scan Many Pages into One PDF

In order to scan multiple pages into one PDF document through C#.NET programming, you may need to add the following dlls to your C# TWAIN scanning project.











or RasterEdge.Imaging.TIFF.dll: this is only needed for scanning many pages to TIFF file

C# TWAIN Scanning Events: Scan Many Pages into One PDF

To accomplish this kind of C#.NET TWAIN scanning, it is indispensible to set up some events to assist with the process of scanning from device and convert the images obtained to form a PDF document.

AcquireCanceled: Raised if C# user cancels TWAIN acquisition process.

AcquireCompleted: Raised when the scanner has finished scanning the last page.

ImageAcquired: Raised each time the scanner finishes scanning a page.

C# TWAIN Scanning Demo Code: Scan Many Pages into One PDF

C# developers can use the following demo code to scan multiple pages into one PDF document in C#.NET project within seconds. Note: you need to reference above mentioned DLL assemblies to your project to complete the following functions.

private bool _acquireCanceled;
private List<REImage> _imageList;

public void ScanImages()
      _acquireCanceled = false;
      Acquisition myAcquisition = new Acquisition();
      myAcquisition.AcquireCanceled += new AcquireCanceledEventHandler(OnAcquireCanceled);
      myAcquisition.AcquireCompleted += new AcquireCompletedEventHandler(OnAcquireCompleted);
      myAcquisition.ImageAcquired += new ImageAcquiredEventHandler(OnImageAcquired);

      TWAINDevice device = myAcquisition.DefaultDevice;
      device.ScanSetting.ShouldTransferAllPages = true;
      _imageList = new List<REImage>();

private void OnImageAcquired(object sender, ImageAcquiredEventArgs args)
      if (args.OutputImage != null)
            // add scaned images to image collection

private void OnAcquireCanceled(object sender, EventArgs args)
      _acquireCanceled = true;

private void OnAcquireCompleted(object sender, AcquireCompletedEventArgs args)
      if (_acquireCanceled)

      // form a PDF document using image collection scanned
      PDFDocument doc = new PDFDocument(_imageList.ToArray());

      // save PDF document

      // do some extra work to finish composing the PDF document

      //// get a TIFF document using similar operation
      // TIFFDocument doc = new TIFFDocument(_imageList.ToArray());

      //// save TIFF document
      // doc.Save(@"c:\scannedTiff.tif");
      // doc.Dispose();