Hi
foreach (Aspose.Pdf.Page page in document.Pages)
{
// Get the link annotations from particular page
Aspose.Pdf.InteractiveFeatures.Annotations.AnnotationSelector selector = new Aspose.Pdf.InteractiveFeatures.Annotations.AnnotationSelector(new Aspose.Pdf.InteractiveFeatures.Annotations.LinkAnnotation(page, Aspose.Pdf.Rectangle.Trivial));page.Accept(selector); <span style="color:green;">// Create list holding all the links</span> System.Collections.<span style="color:#2b91af;">IList</span> list = selector.Selected; <span style="color:green;">// Iterate through invidiaul item inside list</span> <span style="color:blue;">foreach</span> (Aspose.Pdf.InteractiveFeatures.Annotations.<span style="color:#2b91af;">LinkAnnotation</span> a <span style="color:blue;">in</span> list)
{
string url = (a.Action as Aspose.Pdf.InteractiveFeatures.GoToURIAction).URI;
if (url == “https://www.aspose.com/community/forums/addpost.aspx?ForumID=20”)
{
Console.WriteLine("
Destination: " + (a.Action as Aspose.Pdf.InteractiveFeatures.GoToURIAction).URI + “
”);
a.Action = new GoToURIAction(@“www.google.com”);
break;
}
}
}
document.Save(filename1);
It changes the URL of the hyperlink but not the text. How to change the display text, I tried two methods
simple text replace which replaced but I can see a long underline after the hyperlink text
then I tried the following…
// a is retrieved from the above code ***
TextFragmentAbsorber ta = new TextFragmentAbsorber();
Aspose.Pdf.Rectangle rect = a.Rect;
rect.LLX -= 10;
rect.LLY -= 10;
rect.URX += 10;
rect.URY += 10;
ta.TextSearchOptions = new TextSearchOptions(rect);
ta.Visit(document.page); // page is coming from the above logic<span style="color:green;">// Change color and text.</span> <span style="color:blue;">foreach</span> (<span style="color:#2b91af;">TextFragment</span> tf <span style="color:blue;">in</span> ta.TextFragments) { tf.TextState.ForegroundColor = Aspose.Pdf.<span style="color:#2b91af;">Color</span>.Red; tf.Text = <span style="color:#a31515;">"Click Here"</span>; } <span style="color:blue;">break</span>;</pre><pre style="font-family: Consolas; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;"><br></pre><pre style="font-family: Consolas; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;">but this replaces the text but many times as attached(after.img), "Click Here" is appeared many times in the same sentence and the hyperlink format (underline and blue colored text are not disappearing from the previous long URL)</pre><pre style="font-family: Consolas; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;">It would be helpful if you give me some suggestion to resolve this issue ,its bit urgent.</pre><pre style="font-family: Consolas; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;">otherwise, what is the best way to delete the existing hyperlinks (text and url) and add a new one at the same location? can I have the sample code ?</pre><pre style="font-family: Consolas; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;"><br></pre><pre style="font-family: Consolas; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;">Please check the attached images.</pre><pre style="font-family: Consolas; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;">Regards</pre><pre style="font-family: Consolas; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;">Sam.</pre><pre style="font-family: Consolas; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;"><br></pre><pre style="font-family: Consolas; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;"><br></pre></pre></div>