We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

ASPOSE.OCR reads only one character from pdf image

I have one doubt, I am using below code to read text from an image of a pdf file but it returns only single line I want to read the whole file text. Here is my code which ASPOSE.OCR is given.

AsposeOcr libVar = new AsposeOcr();
var slResult = libVar.RecognizeLine(@“D:\ExtractText\Pdf_mages\637590973339132665_out.JPG”);

slResult return only one word i.e “s”.

Please help me. Thank you

@Anil1995

Could you please make sure that you are using the API with a valid or 30-days free temporary license? In case issue still happens, please share your sample image with us so that we can test the scenario in our environment and address it accordingly.

Hi Asad, I have attached the image file which I want to read please check and confirm me. Thank you.637605038128338394_out.jpg (347.9 KB)

@Anil1995

The RecognizeLine() method is used for the image that contains single line of text. Please use below line to recognize text and let us know in case you face any issue:

var slResult = libVar.RecognizeImage("637605038128338394_out.jpg");

Hi @asad.ali I’m using the following code given by you
var slResult = libVar.RecognizeImage(“637605038128338394_out.jpg”);
but it returns following text:-

BalatiOnly CGtdvilASOSGPDECOpDight202-2024SDOSPyL
Senator Justo S. Quitugua, M.Ed.
AGENDA
'. Old Business
a. Referred Legislation

************* Trial Licenses *************

I want to read the whole text from that image file, it return only few lines. Can you please check and confirm me.
I have attached the file which I want to read the text. Thanks in advance.637606771327100809_out.jpg (283.9 KB)

@Anil1995

This looks like a limitation of not using a valid license as we were able to extract all text from the image. As shared in our earlier response, please set the license before using the API and let us know in case you still face any issues. You can obtain a free temporary license from the link shared in our previous response.

Thanks @asad.ali for your quick response. We will definitely go with valid license. I have one more doubt, I want to save my file in memory stream and will fetch the details from there. I used the aspose code from documentation but it won’t work. Can you please check and confirm me. Below is my code:-

PdfExtractor pdfExtractor = new PdfExtractor();
pdfExtractor.BindPdf(pdffile);

            pdfExtractor.ExtractText();

            MemoryStream tempMemoryStream = new MemoryStream();
            pdfExtractor.GetText(tempMemoryStream);


            using (MemoryStream ms = new MemoryStream())
            using (FileStream file1 = new FileStream(@"D:\ExtractText\Pdf_mages\637606771327100809_out.JPG", FileMode.Open, FileAccess.Read))
            {
                file1.CopyTo(ms);
                var Result = libVar.RecognizeImage(@"D:\ExtractText\Pdf_mages\637606771327100809_out.JPG");
                Result = libVar.RecognizeImage(ms);
                Console.WriteLine(Result);
            }

            objConverter.Close();
            Console.ReadKey();

How can I store the record in memory stream and read from memory stream please share the code. Thank you

@Anil1995

Please try using the below code snippet and let us know in case you still face any issue:

Document pdfDocument = new Document(file);
ImagePlacementAbsorber abs = new ImagePlacementAbsorber();
pdfDocument.Pages.Accept(abs);

foreach (ImagePlacement imagePlacement in abs.ImagePlacements)
{
 string slResult = "";
 XImage ximage = imagePlacement.Image;
 AsposeOcr libOcr = new AsposeOcr();

 using (MemoryStream ms = new MemoryStream())
 {
  ximage.Save(ms);
  ms.Position = 0;
  slResult = libOcr.RecognizeImage(ms);
 }
 Console.WriteLine(slResult);
}