I am currently developing a simple DMS solution. First step is to acquire the image from the scanner to a temporary location (sy C:\temp\scan.pdf). After that I ocr the file and save a new pdf to a different location (say c:\ocrfiles\scan.pdf) However, I'm not able to delete the temporary file after processing it.
Here is the code I'm using:
Code: Select all
Private Sub DoOCR(ByVal path As String, ByVal outputPath As String)
Dim pdfID As Integer
Dim InputPDFID As Integer
Dim ImageID As Integer
pdfID = oGdPictureImaging.PdfOCRStart(outputPath, True, "", "", "", "", gvUser.UserName)
InputPDFID = oGdPictureImaging.PdfReaderLoadFromFile(path)
If InputPDFID <> 0 Then
For i As Integer = 1 To oGdPictureImaging.PdfReaderGetPageCount(InputPDFID)
oGdPictureImaging.PdfReaderSelectPage(InputPDFID, i)
ImageID = oGdPictureImaging.PdfReaderRenderPageToGdPictureImage(InputPDFID, 300, True)
If ImageID <> 0 Then
If TxxConvertToBW1Bit.Checked Then 'BW
oGdPictureImaging.ConvertTo1Bpp(ImageID)
End If
oGdPictureImaging.PdfAddGdPictureImageToPdfOCR(pdfID, ImageID, TxcDocLanguage.Value, System.IO.Path.Combine(Application.StartupPath, "ProIT_OCR"), "")
If oGdPictureImaging.GetStat <> GdPicture.GdPictureStatus.OK Then
MsgBox("Seite " + Str(i) + " konnte nicht gelesen werden. Error: " + oGdPictureImaging.GetStat.ToString)
End If
oGdPictureImaging.ReleaseGdPictureImage(ImageID)
Else
MsgBox("Seite kann nicht gerendert werden. " + Str(i))
End If
Next i
Else
MsgBox("Datei kann nicht geöffnet werden!")
End If
oGdPictureImaging.ReleaseGdPictureImage(InputPDFID)
oGdPictureImaging.PdfOCRStop(pdfID)
oGdPictureImaging.PdfEndPdf(InputPDFID)
My.Computer.FileSystem.DeleteFile(path)
End Sub
Code: Select all
My.Computer.FileSystem.DeleteFile(path)
. Which method do I need to call to release all handles?The process cannot access the file 'C:\temp\scan.pdf' because it is being used by another process.
Thank you for your help!
Mike