Diese Seite mit anderen teilen ...

Informationen zum Thema:
WinDev Forum
Beiträge im Thema:
Erster Beitrag:
vor 5 Jahren, 4 Monaten
Letzter Beitrag:
vor 4 Jahren, 11 Monaten
Beteiligte Autoren:
Sascha77, Abigail Klinton, Vassilis Boutsikas

[WD 17]Scan multiple pages into one pdf

Startbeitrag von Sascha77 am 26.02.2013 16:32

HI all,

currentlly i am facing the problem that i can´t mange to scan multiple pages into one pdf file.
I found a few examples in the forum, but nothing worked :(

when i do call

it does not return after the first page has been scanned. It comes back after all pages are processed and therefore TwainState does not help me at this place...

does somebody manged to let that fly ?

Thanks for your help


The following code is the solution you want.

//------- With the TwainMultiPageToPDF procedure:
// Summary: Saves the documents found in the driver of the Twain device in a PDF file
// Syntax:
// Parameters:
// PDFName: Name of PDF in output
// Quality (int - default value=100):
// UserInterface (default value=0):
// TypeImages (default value=0):
// NumberBitsPerPixel (default value=0):
// ResolutionImages (default value=0):
// ContrastImages (default value=0):
// BrightnessImages (default value=0):
// DuplexMode (default value=0):
// AutoLoad (default value=1):

// The lower the image quality, the higher the compression rate of the image will be
// and the smaller the size of the file will be.
// False (default value) if the user interface of the Twain device must be displayed.
// When saving the document, the will be proposed by default.
// Type of image used to save the document (classified by order of color management)
// Amount of information about the colors (to display or to print each pixel in an image).
// The larger the number of bits per pixel, the sharper the color rendering will be.
// Number of pixels per inch (possible values according to the device used).
// Contrast of the image (value included between -1000 and 1000).
PROCEDURE TwainMultiPageToPDF(PDFName, Quality is int=100, UserInterface=False, TypeImages=0, NumberBitsPerPixel=0, ResolutionImages=0, ContrastImages=0, BrightnessImages=0, DuplexMode=False, AutoLoad=True)

ListTempFiles is List of strings
// Does the destination file exist?
IF fFileExist(PDFName) THEN
// Yes, delete the file
IF NOT fDelete(PDFName) THEN
// Error if the deletion failed
// Generate a PDF with the printout commands
iDestination(iGenericPDF, PDFName)
// Name of temporary destination file
NameScannedFile is string
ResScan is boolean
NbPage is int = 0
// A4 format
TwainScanZone(0, 0, 210, 297)
// Scan
IF TypeImages = TwainBlackWhite THEN
// If B&W, a scan in a monochrome BMP is smaller
NameScannedFile = fExtractPath(fTempFile(), fFileName+fDrive+fDirectory) + ".BMP"
ResScan = TwainToBMP(NameScannedFile, UserInterface, TypeImages, 1, ResolutionImages, ContrastImages, BrightnessImages, DuplexMode, AutoLoad)
// Otherwise, in a JPG
NameScannedFile = fExtractPath(fTempFile(), fFileName+fDrive+fDirectory) + ".JPG"
ResScan = TwainToJPEG(NameScannedFile, Quality, UserInterface, TypeImages, NumberBitsPerPixel, ResolutionImages, ContrastImages, BrightnessImages, DuplexMode, AutoLoad)
// Scan OK?
// Yes, stores the name of the temporary image file (to delete it at the end)
Add(ListTempFiles, NameScannedFile)
// Is it the first page?
IF NbPage > 1 THEN
// no, therefore page skip
// To printout on the entire page
iPrintImage(NameScannedFile, 0, 0, iPageWidth(), iPageHeight(), iHomotheticDisplay)
// User cancelation (on the window for canceling the printout)?
IF iDocumentCanceled() THEN BREAK
// Problem with the scan, stop?
IF NOT YesNo("Continue with Scan?") THEN BREAK
// More pages?
IF TwainState() = tsUnloaded THEN BREAK
// Yes, therefore next page
// Returns the number of scanned pages
// Has the printout started?
IF NbPage > 0 THEN
// Yes, therefore end of generation of PDF (end of printout)
// Delete the temporary images
FOR EACH ELEMENT NameScannedFile OF ListTempFiles

The secret is to set the AutoLoad flag to True, in order to scan multiple pages to ONE PDF.

Good luck


von Vassilis Boutsikas - am 27.02.2013 05:35
Hi Vassilis,

you made my day! I missed the autoload property! now the code works perfect!

Thanks for your help


von Sascha77 - am 27.02.2013 07:32
Hi ,i'd like to suggest you to create a pdf online viewer to scan pdf files.That would be more convinient to your work.

von Abigail Klinton - am 19.08.2013 03:57
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.