Scan to a multi-page PDF or TIFF file in VB

A sample application using TwainControlX

This example shows how to acquire a series of images from a TWAIN device and save these images as a single multi-page PDF file. This can be done either using an Automatic Document Feeder (ADF) or by scanning single pages and building the file one image at a time.

To use this demo, you will need to download two files:

Trial version of the ActiveX control TwainControlX. 1.5MB)

Zip file of VB demo project. (4kB)

Install TwainControlX, then extract the VB demo files from Open Visual Basic, and open the project TCX_Mult2.vbp.

The project consists of a single form, fMain. All the code is included in this form, there are no other modules. Run the project and click one of the three buttons.

VB Multiple Scan Demo

The first button starts acquiring images in MultiImage mode. This normally requires a scanner with an ADF, but can also be possible with some webcams. When all images have been acquired, a multi-page PDF file "Multi.pdf" is saved. The files will be saved in the default working directory for VB, so edit the code to specify a different path if you want to save them somewhere else.

The second or third buttons start acquiring images one at a time. After each one, a message box asks the user whether to continue or to stop. The AddToPDF or InsertPDF commands are used to build a multi-page PDF file from the individual images.

After each image is acquired, the code in 'Twain1_OnAcquire' will run. This displays the current image in a VB Image control.

Default settings for the image size and resolution will be used. This usually means that the image is too big to display in the Image control, so only the top left portion of the image will be seen on screen. The whole image will be saved to file.

Multi-page TIFF files can be created instead of PDF files by modifying the code and replacing PDF functions with the corresponding TIFF functions, i.e., replace AddToPDF with AddToTIF, WritePDF with WriteTIF etc.