How to Start Tutorials Troubleshooting Main Operations Convert PDF Read PDF Edit PDF PDF Report Generator Work with PDF Modules PDF Document PDF Pages Text Image Graph & Path Annotation, Markup & Drawing Redaction Security Digital Signature Forms Watermark Bookmark Link File Attachment File Metadata Printing Work with Other SDKs Barcode read Barcode create OCR Twain

C# PDF Parser Library
Acquire or Save images through Twain, embed into PDF file pages in WinForms, asp.net. Free Download


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













Overview


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.

Using our 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.





Scan multiple images into one PDF


To accomplish this kind of C#.NET TWAIN scanning, it is indispensable 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#.NET TWAIN Scanning Demo Code: Scan multiple images into one PDF


Following C# demo code can 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<RasterImage> _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.Open();
            device.ScanSetting.ShouldTransferAllPages = true;
            _imageList = new List<RasterImage>();
            device.Acquire();
        }

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

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

        private void OnAcquireCompleted(object sender, AcquireCompletedEventArgs args)
        {
            if (_acquireCanceled)
                return;
            Bitmap[] bmps = new Bitmap[_imageList.Count];
            int index = 0;
            foreach (RasterImage image in _imageList)
            {
                bmps[index++] = image.ToBitmap();
            }
            index =0;
            REImage[] imageList = new REImage[bmps.Length];
            foreach (Bitmap bmp in bmps)
            {
                imageList[index++] = new REImage(bmp);
            }

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

            // save PDF document
            doc.Save(@"c:\ScannedPDF.pdf");
            doc.Dispose();
        }