I have the simplest WinForms app with file path textbox, output text box and a button. I test PDF OCR capabilities, but at processor.PerformOCR it throws error:
Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at Syncfusion.OCRProcessor.Native.OCRApi.InitializeDataPath(IntPtr pt, String path, String lang)
at Syncfusion.OCRProcessor.OCRProcessor.DoOCR(String[] args)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Program.Main(String[] args)
This is the code, all there is:
try
{
SyncfusionLicenseProvider.RegisterLicense("VALID LICENSE KEY HERE");
//Initialize the OCR processor by providing the path of tesseract binaries(SyncfusionTesseract.dll and liblept168.dll)
using (OCRProcessor processor = new OCRProcessor(@"C:\Temp\TesseractBinaries\3.02\"))
{
//Load a PDF document
PdfLoadedDocument lDoc = new PdfLoadedDocument(file.Text);
//Set OCR language to process
processor.Settings.Language = Languages.English;
//Process OCR by providing the PDF document and Tesseract data
output.Text = processor.PerformOCR(lDoc, @"C:\Temp\TesseractData");
//Save the OCR processed PDF document in the disk
lDoc.Close(true);
}
}
catch(Exception ex)
{
output.Text = ex.Message;
}
TesseractBinaries does contain the required *.dll files, TesseractData contains *.traineddata files, Project itself has NuGet references to Syncfusion packages. Actual .sln attached.
I originally tested this on Windows Server 2012R2 within SharePoint 2016 Event Handler, but it gave same error as now also on my local machine (Windows 10) in a test WinForms application.
Attachment:
OCRTester_f653dc74.zip