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

Free Support Forum - aspose.com

Add the after and before blue color text of links to link annotation

Hi Team,
In attached pdf, where ever the blue text found, check the entire blue text has link, if not i have to add entire blue text to the existing link. could you please help me with the code i required.

Thanks,
Harish G.bluetext.pdf (17.6 KB)

@HarishGali

We are trying to prepare a sample code snippet for you and will get back to you shortly.

Thank you, I am eagerly waiting for the code snippet.

@HarishGali

This is a custom scenario and we are afraid that the API does not offer any direct method or the functionality to achieve your requirements. However, we are trying to come up with a workaround and will inform you as soon as we have some. Please give us little time.

Thank you asad, i request you to do ASAP.

@HarishGali

We tried to achieve your requirements using the code below but unfortunately, API was unable to recognize the text on color basis:

Document doc = new Document(dataDir + "bluetext.pdf");
foreach (Aspose.Pdf.Page page in doc.Pages)
{
 List<string> additionList = new List<string>();

 var AnnotationList = page.Annotations.Where(x => x.AnnotationType == AnnotationType.Link);
 if (AnnotationList.Any())
 {
  TextFragmentAbsorber textAbsorber = new TextFragmentAbsorber();
  page.Accept(textAbsorber);
  foreach(TextFragment fragment in textAbsorber.TextFragments)
  {
   if(fragment.TextState.ForegroundColor == Color.Blue)
   {
    foreach(var annot in AnnotationList)
    {
     if(fragment.Text.Contains(annot.Contents))
     {
      var link = annot.Hyperlink;
      var rect = fragment.Rectangle;

      page.Annotations.Delete(annot);

      LinkAnnotation linkannot = new LinkAnnotation(page, rect);
      linkannot.Hyperlink = link;
      page.Annotations.Add(linkannot);
     }
    }
   }
  }
 }
}
doc.Save(dataDir + "updated.pdf");

Therefore, a ticket as PDFNET-51986 has been logged in our issue tracking system to further investigate the issue. We will look into its details and keep you posted with the status of its correction. Please be patient and spare us some time.

We are sorry for the inconvenience.

Thank you for quick response. this works good, but one issue is if the blue text split into two text fragments, then there is disturbance in requirement.so, please try to give solution for this issue.

@HarishGali

It looks like the API is behaving differently on different machines. On our end, it was not able to recognize the text on the basis of color. Nevertheless, can you please share the output PDF generated at your end?

Hi ali,

please find first link in first page in attached document, the blue text split into two text fragments,

also annot.Contents showing empty always in my machine. unable to achieve the good output with that, could please give me the solution.

Thank you.bluetext3.pdf (76.9 KB)

@HarishGali

Another issue as PDFNET-52002 has been logged in our issue tracking system for this new case. We will definitely investigate it as well on first come first serve basis and let you know as soon as the ticket is resolved. Please be patient and spare us some time.

We are sorry for the inconvenience.

any solution??

@HarishGali

Please note that the tickets have recently been logged in our issue tracking system and they are pending for analysis. They will be investigated on first come first serve basis as per free support policies. Once they are completely investigated, we will be able to share some news about their fix ETA. Please give us some time.

We are sorry for the inconvenience.