I just upgraded my Aspose.OCR-nuget-package from version 17.11.0 to 19.8.1, which broke the following code at “ocrEngine.Process()”:
Aspose.Pdf.License licPDF = new Aspose.Pdf.License();
licPDF.SetLicense("Aspose.Total.lic");
Aspose.Pdf.Document pdfDoc = null;
Aspose.OCR.License licOCR = new Aspose.OCR.License();
licOCR.SetLicense("Aspose.Total.lic");
Aspose.OCR.OcrEngine ocrEngine = new Aspose.OCR.OcrEngine();
using (var ms = new MemoryStream(File.ReadAllBytes(Path.Combine("pathToDocument", "Beispiel3.pdf"))))
{
pdfDoc = new Aspose.Pdf.Document(ms);
if (pdfDoc != null)
{
var sb = new StringBuilder();
foreach (var page in pdfDoc.Pages)
{
using (var imageStream = new MemoryStream())
{
var jpegDevice = new Aspose.Pdf.Devices.JpegDevice(new Aspose.Pdf.Devices.Resolution(300), 100);
jpegDevice.Process(page, imageStream);
imageStream.Position = 0;
ocrEngine.Image = Aspose.OCR.ImageStream.FromStream(imageStream, ImageStreamFormat.Jpg);
if (ocrEngine.Process())
{
Console.WriteLine(ocrEngine.Text);
}
}
}
}
}
The error states:
MyNamespace.UnitTest.AsposeTest_OCR_PDF_to_TXT.Test_AsposeOCR_PDFToText:
Aspose.OCR.OcrException : Error occurred during recognition.
----> System.IO.FileNotFoundException : The file “pathToMyProject\UnitTest\bin\Debug\data” does not exist.
StackTrace:
at Aspose.OCR.OcrEngine. ()
at Aspose.OCR.OcrEngine.Process()
at MyNamespace.UnitTest.AsposeTest_OCR_PDF_to_TXT.Test_AsposeOCR_PDFToText() in pathToMyProject\UnitTest\AsposeTest_OCR_PDF_to_TXT.cs: line 74.
–FileNotFoundException
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.GetAttributes(String path)
at .(String , String )
at .(IEnumerable1 ) at ..ctor(IEnumerable
1 )
at …ctor()
at …ctor()
at …ctor( , Boolean )
at .( , Boolean )
at Aspose.OCR.OcrEngine.()
Testing the nuget-version 19.8.0 replicates the same error.
Please find the pdf-file attached:
Beispiel3.pdf (70.6 KB)
Best regards.