ExtractText method throws Indexoutofrange exception when using out TextLineCollection parameter

Dear Team,


In Winforms application, when attempting to extract text from a PDF file into Textlines, the below exception is thrown:


System.ArgumentOutOfRangeException: 'Index was out of range. Must be non-negative and less than the size of the collection.

Parameter name: index'


Sample code:


 //Load first page

 PdfPageBase page = loadedDocument.Pages[0];

 TextLines tlines= new TextLines();

 //Extract text from first page

 page.ExtractText(out tlines);  //Exception in this line


 //Close the document

 loadedDocument.Close(true);



Similar bug raised for Textdata collection:

[Bug] System.IndexOutOfRangeException when ExtractText | WinForms Forums | Syncfusion


Thanks

Santhosh



11 Replies

IJ Irfana Jaffer Sadhik Syncfusion Team November 14, 2024 10:34 AM UTC

Hi Santhosh,


We have tried to reproduce the reported behavior with the provided details on our end but we were unable to reproduce the reported issue with the pdf in the [Bug] System.IndexOutOfRangeException when ExtractText | WinForms Forums | Syncfusion. We have attached the sample for your reference. Please try this on your end and let us know the result.


Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/NetFramework-511199399


If you are still facing issue with the other document. Please share with us the modified sample with us. So that we can assist with you further in this. 


Regards,

Irfana J.



SK Santhosh Kumar replied to Irfana Jaffer Sadhik November 14, 2024 10:48 AM UTC

Dear Irfana,


Please try with the attached file. This file throws an error.

Also, I need some help with performing OCR on a JPEG file. The OCRed text is garbled/corrupted. When I convert the image as PDF, the resultant searchable PDF looks fine. But reading from the searchable pdf or the OCRed text from the image are not readable.


Image_3430_1731581197185


Please provide me a sample of the OCR code in Winforms.


Thanks


Santhosh



SK Santhosh Kumar November 14, 2024 10:56 AM UTC

I have attached the pdf.


Attachment: AJAYDASS_104dc3a0.zip


AM Arumugam Muppidathi Syncfusion Team November 15, 2024 02:46 PM UTC

Hi Santhosh Kumar,


Currently, we are creating a sample to perform OCR on Image without OCRed text corrupted in Winforms.  We will update further details on November 19th, 2024.


Regards,
Arumugam M



AM Arumugam Muppidathi Syncfusion Team November 19, 2024 04:26 PM UTC

Hi Santhosh Kumar,


Upon further analysis, we have created sample Winforms application to perform OCR with the provided image.  The resultant OCRed text was accurate as expected and not corrupted.  We have attached the sample and output document below for your reference


Sample: 
Perform-OCR207739126
Output: OCR_Result-216355667


Please try the above sample and let us know the result.  Kindly get back to us if you need any further assistance in this.


Regards,
Arumugam M



SK Santhosh Kumar November 20, 2024 05:36 AM UTC

Dear Arumugam,


The sample also works for some files and not others.

The PDF file throws an error if I try to extract the files into textlines (the original question raised here). I'm able to extract text into a string, list<textdata> etc. though.

The JPEG file when I perform OCR and save it as a searchable pdf, the resultant pdf works. but when i extract the data from the pdf document, the text is not what as per text in the image.


I have attached two sample files one pdf and a JPEG file for your analysis. Two screenshots are also attached one of an exception while performing OCR and another the improper text read from the image file when extracting from the resultant searchable PDF. 


I'm trying to import the data in the image and pdfs into SQL server database.  I understand the files could be problematic, but we currently have a third-party application where these two files are read properly, and the data is imported properly. We want to move to an in-house developed solution for this and are evaluating the Syncfusion PDF and OCR components for this.


Is there any way to identify such files and read them correctly from some properties. What adjustments need to be done in the code to achieve the desired result?


Thanks


Santhosh


Attachment: Sample_files_bbb5f41f.zip



AM Arumugam Muppidathi Syncfusion Team November 21, 2024 04:20 PM UTC

Hi Santhosh,


We have checked the reported issue on our end.  Upon further analysis, you have issue with text extraction in PDF document it seems.  We were able to reproduce the reported issue regarding text extraction.  Currently, we are validating this and we will update further details on November 25th, 2024.

Kindly get back to us, If you have any queries regarding OCR.


Regards,

Arumugam M



RS RaashithAhamed SahulHameed Syncfusion Team November 25, 2024 01:16 PM UTC

Hi Santhosh,

We have confirmed the issue “ExtractText method throws Indexoutofrange exception while using TextLinecollection API” as a defect in our product and we will include the fix in weekly release on 17th December 2024


Please use the below feedback link to track the status of the reported bug.

https://www.syncfusion.com/feedback/63380/extracttext-method-throws-indexoutofrange-exception-while-using-textlinecollection


Note: If you require a patch for the reported issue in any of our Essential Studio Main or SP release version, then kindly let us know the version, so that we can provide a patch in that version based on our SLA policy.


Disclaimer: “Inclusion of this solution in the weekly release may change due to other factors including but not limited to QA checks and works reprioritization.”

Regards,

Raashith Ahamed




IJ Irfana Jaffer Sadhik Syncfusion Team December 17, 2024 12:17 PM UTC

Hi Santhosh,


The weekly release will be postponed to tomorrow, December 18, 2024. We kindly ask for your patience and understanding in the meantime. 


 

Regards,

Irfana J.



IJ Irfana Jaffer Sadhik Syncfusion Team December 19, 2024 06:26 AM UTC

Hi Santhosh,


We have included the fix for this issue “ExtractText method throws Indexoutofrange exception while using TextLinecollection API ” in our latest weekly release (28.1.35) .Please download the Nuget from the below link



Root Cause: While extracting the text, we assigned the bounds, font related things to the glyph. In this document, index is greater than the glyph list count therefore it causes Index out of range exception occurs while extracting the text.

Regards,
Irfana J.


SK Santhosh Kumar December 19, 2024 08:46 AM UTC

Thank you so much! 


Loader.
Up arrow icon