Aspose.Pdf.Page.Accept method InvalidCastException

Hi,

When trying to read the text content of some Pdf files with Aspose.Pdf.Text.TextAbsorber class, the call to Aspose.Pdf.Page.Accept method throws an InvalidCastException. The error is not encountered in all Pdf files, so a file which can be used to reproduce the error is attached.

The Accept method of the code below throw the exception when the Document file is created by using the file attached:


var doc = new Document(@“C:\pdf\1897turkyunansavasi.pdf”);
{
var visitor = new TextAbsorber();
try
{
doc.Pages[1].Accept(visitor);
}
catch (InvalidCastException e)
{
Console.WriteLine(e.Message);
}
}

We encounter a similar error when trying to search a phrase in the file, in order to highlight the phrase when viewing:

var visitor = new TextFragmentAbsorber(“1897”);
try
{
doc.Pages[1].Accept(visitor);
}
catch (InvalidCastException e)
{
Console.WriteLine(e.Message);
}

Thank you for your help in advance.

Best Regards

HI Huseyin,


Thanks for contacting support.

I have tested the scenario using Aspose.Pdf for .NET 17.2.0 and have not found any exception. I will appreciate if you could share more details of your environment along with Aspose.Pdf API version. It will help us to reproduce the issue in our environment for rectification.

We are sorry for the inconvenience.

Best Regards,

Hi Fahad,

Thanks for your support.

I have also tried using Aspose.Pdf for .NET 17.2.0, yet the problem persists. The culture of the environment that the code is tested is “tr-TR”. That is the culture we expect to be in many of our clients’ systems. I have tried changing the culture to “en-US” and the code ceased to throw exception.

I believe you will able to reproduce the error if you change the culture of the thread to “tr-TR”.


var tr = new CultureInfo(“tr-TR”);
CultureInfo.DefaultThreadCurrentCulture = tr; // Only in .NET 4.5
var doc = new Document(@“C:\pdf\1897turkyunansavasi.pdf”);
<span style=“font-family: “Courier New”; font-size: small; background-color: rgb(255, 255, 255);”>var visitor = new TextAbsorber();
try
{
<span style=“font-family: “Courier New”; font-size: small; background-color: rgb(255, 255, 255);”> doc.Pages[1].Accept(visitor);
}
<span style=“font-family: “Courier New”; font-size: small; background-color: rgb(255, 255, 255);”>catch (InvalidCastException e)
{
<span style=“font-family: “Courier New”; font-size: small; background-color: rgb(255, 255, 255);”> Console.WriteLine(e.Message);
}

Best Regards

Hi Huseyin,


Thanks for sharing further details.

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Arial; -webkit-text-stroke: #000000} span.s1 {font-kerning: none}

I have tested the scenario and have managed to reproduce the problem that using culture as "tr-TR" for your provided PDF document Aspose.Pdf.Page.Accept method throws an exception. For the sake of correction, I have logged it as PDFNET-42381 in our issue tracking system. We will further look into the details of this problem and will keep you posted on the status of correction.


Please be patient and spare us little time. We are sorry for this inconvenience.


Best Regards,