I tried your .net example "PDF to PDF-OCR". Because I have to process more than one PDF, I put the code into a FOR EACH loop.
In the begining I initialize a new oGdPictureImaging object and in the end of each PDF I set oGdPictureImaging = Nothing. Unfortunately there is no dispose method.
Never the less it seems to be that there are more than one oGdPictureImaging objects and I get the following error:
Here is my code:System.Exception: OCR exception at step 201: Ein Aufrufziel hat einen Ausnahmefehler verursacht.
Source: mscorlib
StackTrace: bei System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
bei System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
bei System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
bei System.Delegate.DynamicInvokeImpl(Object[] args)
bei ?.?.?(Int32 ?, Int32 ?, Int32 ?, Int32 ?, Int32 ?, TesseractDictionary ?, String ?, String ?, IntPtr& ?, Int32& ?, Int32 ?)
bei ?.?.?(Int32 ?, Int32 ?, Int32 ?, Int32 ?, Int32 ?, TesseractDictionary ?, String ?, String ?, IntPtr& ?, Int32& ?, Int32 ?)
bei GdPicture.GdPictureImaging.PdfAddGdPictureImageToPdfOCR(Int32 PdfID, Int32 ImageID, TesseractDictionary Dictionary, String DictionaryPath, String CharWhiteList)
Code: Select all
For Each file In OpenFileDialog1.FileNames
oGdPictureImaging = New GdPicture.GdPictureImaging
Dim InputFileName As String = file
Dim OutputFileName As String = _OutputDir & "/" & InputFileName.Substring(InputFileName.LastIndexOf("\") + 1, InputFileName.Length - InputFileName.LastIndexOf("\") - 1)
Dim ImageID As Integer
Dim Dict As GdPicture.TesseractDictionary
Dim InputPDFID As Integer
Dim PdfID As Integer
Dim Resolution As Integer = Val(TextBox2.Text)
oGdPictureImaging.SetLicenseNumber("")
Dict = GdPicture.TesseractDictionary.TesseractDictionaryGerman
PdfID = oGdPictureImaging.PdfOCRStart(OutputFileName, CheckBox1.Checked, "", "", "", "", "")
InputPDFID = oGdPictureImaging.PdfReaderLoadFromFile(file)
If InputPDFID <> 0 Then
For i As Integer = 1 To oGdPictureImaging.PdfReaderGetPageCount(InputPDFID)
oGdPictureImaging.PdfReaderSelectPage(InputPDFID, i)
ImageID = oGdPictureImaging.PdfReaderRenderPageToGdPictureImage(InputPDFID, Resolution, True)
If ImageID <> 0 Then
If CheckBox2.Checked Then 'BW
oGdPictureImaging.ConvertTo1Bpp(ImageID)
End If
oGdPictureImaging.PdfAddGdPictureImageToPdfOCR(PdfID, ImageID, Dict, Application.StartupPath & "/OCR", "")
If oGdPictureImaging.GetStat <> GdPicture.GdPictureStatus.OK Then
MsgBox("OCR problem on page " + Str(i) + ". Error: " + oGdPictureImaging.GetStat.ToString)
End If
oGdPictureImaging.ReleaseGdPictureImage(ImageID)
Else
MsgBox("Can't render page " + Str(i))
End If
Next i
Else
MsgBox("Can't open file: " & InputFileName)
End If
oGdPictureImaging.PdfOCRStop(PdfID)
oGdPictureImaging = Nothing
Next
Thanks Olaf