Extract title of the linked text from PDF using Aspose.PDF for .NET - Title is not showing

Hello,

This is the code snippet we are using extract link title.
Aspose.Pdf.Text.TextFragmentAbsorber textFragmentAbsorbernew = new Aspose.Pdf.Text.TextFragmentAbsorber();
textFragmentAbsorbernew.TextSearchOptions = new Aspose.Pdf.Text.TextSearchOptions(newRect);
textFragmentAbsorbernew.Visit(PDFPage);
int FragmentTextlength = 0;
Linktext = “”;
Aspose.Pdf.Rectangle prevFragmentRect = null;
foreach (Aspose.Pdf.Text.TextFragment TextFrag in textFragmentAbsorbernew.TextFragments)
{
if (prevFragmentRect != null && prevFragmentRect.LLY != TextFrag.Rectangle.LLY && prevFragmentRect.URY != TextFrag.Rectangle.URY)
{
Linktext += " " + TextFrag.Text;
}
else
{
Linktext += TextFrag.Text;
}
prevFragmentRect = TextFrag.Rectangle;
if (FragmentTextlength < TextFrag.Text.Length)
{
TextColor = TextFrag.TextState.ForegroundColor.ToString();
FragmentTextlength = TextFrag.Text.Length;
}

But it shows empty for the attached document.
Please let us know how to solve this issue.

Thanks,

Attached the document.

@M_Sowbhagya

We could not find any attached document with your post. Would you please make sure to upload it again.

linktitleissue.pdf (89.4 KB)
I have attached the document. Please let us know how to solve the issue.

Thanks,
Sow

@M_Sowbhagya

We tried following code snippet in order to extract text for links in your PDF and got some results:

Document pdfDocument = new Document(dataDir + "linktitleissue.pdf");
PageCollection pages = pdfDocument.Pages;
foreach (Page p in pages)
{
 foreach (Annotation anno in p.Annotations)
 {
   if (anno.AnnotationType == AnnotationType.Link)
   {
    LinkAnnotation linkAnno = (LinkAnnotation)anno;
    var rect = linkAnno.Rect;
    Aspose.Pdf.Text.TextFragmentAbsorber textFragmentAbsorbernew = new Aspose.Pdf.Text.TextFragmentAbsorber();
    textFragmentAbsorbernew.TextSearchOptions = new Aspose.Pdf.Text.TextSearchOptions(rect);
    textFragmentAbsorbernew.Visit(p);
    if (textFragmentAbsorbernew.TextFragments.Count > 0)
    {
      string text = textFragmentAbsorbernew.TextFragments[1].Text;
    }
  }
 }
}

Would you please try using above code snippet and share your feedback with us. Also, in your previously-shared snippet, the value of “newRect” variable was unknown. Could you please share that with us as well along with the expected results that you want to obtain.