Code: Select all
Private Sub InitScanConfig()
oGdPictureImaging.TwainSetHideUI(True)
oGdPictureImaging.TwainSetIndicators(False)
oGdPictureImaging.TwainSetAutoBrightness(True)
oGdPictureImaging.TwainSetContrast(0)
oGdPictureImaging.TwainSetResolution(200)
oGdPictureImaging.TwainSetAutoFeed(True) 'Set AutoFeed Enabled
oGdPictureImaging.TwainSetAutoScan(True) 'To achieve the maximum scanning rate
oGdPictureImaging.TwainSetPixelType(TwainPixelType.TWPT_RGB) 'RGB
oGdPictureImaging.TwainSetBitDepth(1) ' 1 bpp
End Sub
Private Sub ScanDocuments()
Dim PdfID As Integer
Dim count As Integer
count = 0
Try
If oGdPictureImaging.TwainOpenDefaultSource(Me.Handle) Then
InitScanConfig()
GdViewer1.ZoomMode = ViewerZoomMode.ZoomModeFitToViewer
If Me.chkLegal.Checked = True Then
oGdPictureImaging.TwainSetPaperSize(TwainPaperSize.USLEGAL)
Else
oGdPictureImaging.TwainSetPaperSize(TwainPaperSize.USLETTER)
End If
If Me.rdoDoubleSided.Checked = True Then
oGdPictureImaging.TwainEnableDuplex(True)
ElseIf Me.rdoSingleSided.Checked = True Then
oGdPictureImaging.TwainEnableDuplex(False)
End If
PdfID = oGdPictureImaging.TwainPdfStart(strScannedFilesPath & strFileName & ".pdf", True, "", "", "", "", "")
Do
ImageID = oGdPictureImaging.TwainAcquireToGdPictureImage(Me.Handle)
count = count + 1
If count = 1 Then
Call oGdPictureImaging.SaveAsJPEG(ImageID, strScannedFilesPath & strFileName & ".jpg", 90)
End If
If ImageID <> 0 Then
If Not oGdPictureImaging.IsBlank(ImageID) Then
Call oGdPictureImaging.TwainAddGdPictureImageToPdf(PdfID, ImageID)
oGdPictureImaging.ReleaseGdPictureImage(ImageID)
End If
End If
Loop While oGdPictureImaging.TwainGetState > TwainStatus.TWAIN_SOURCE_ENABLED
oGdPictureImaging.TwainPdfStop(PdfID)
CloseCurrentImage()
Call DisplayImage(strScannedFilesPath & strFileName & ".pdf")
Else
oGdPictureImaging.TwainSelectSource(Me.Handle)
Me.btnScan.Enabled = True
Exit Sub
End If
Call oGdPictureImaging.TwainCloseSource()
Call oGdPictureImaging.TwainUnloadSourceManager(Me.Handle)
Catch ex As Exception
ExceptionHandler(ex, "frmScanDocs_ScanDocuments")
End Try
End Sub