Loading...

Can not delete file after processing

Discussions about image processing in GdPicture.NET using GdPictureImaging.

Can not delete file after processing

Postby proit » Wed Apr 20, 2011 11:05 am

Hi

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


The line
Code: Select all
My.Computer.FileSystem.DeleteFile(path)
allways gives me the follogwin error:
The process cannot access the file 'C:\temp\scan.pdf' because it is being used by another process.
. Which method do I need to call to release all handles?

Thank you for your help!
Mike
Regards, Mike
proit
 
Posts: 6
Joined: Wed Apr 20, 2011 10:28 am
Location: Switzerland

Re: Can not delete file after processing

Postby Loïc » Wed Apr 20, 2011 2:01 pm

Hi Mike,

Please replace:

Code: Select all
oGdPictureImaging.ReleaseGdPictureImage(InputPDFID)


by


Code: Select all
oGdPictureImaging.PdfReaderCloseDocument(InputPDFID)


:)

Let me know if the problem persists.
Loïc Carrère, support team.
www.orpalis.com
User avatar
Loïc
Site Admin
 
Posts: 4442
Joined: Tue Oct 17, 2006 10:48 pm
Location: France

Re: Can not delete file after processing

Postby proit » Wed Apr 20, 2011 2:10 pm

Hi Loïc

Now it works just fine!

Thank you for your help!!

Mike
Regards, Mike
proit
 
Posts: 6
Joined: Wed Apr 20, 2011 10:28 am
Location: Switzerland


Return to Image Processing

Who is online

Users browsing this forum: No registered users and 0 guests