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

Free Support Forum - aspose.com

How to update hyperlink text in pdf using itextsharp in c#

0

down vote

favorite

my requirement is need to update hyperlink and hyperlink text in pdf using Itextsharp in c#.net application.I can able to update hyperlink address
but how to change hyperlink text

for example : hyperlink is : http://www.google.com hyperlink text is : ClickHere

I want change “ClickHere” to “SearchHere”

Any help,Appreciated

Hi Ashok,


Thanks for your inquiry. I am afraid it is Aspose community forum. For Itextsharp help, please use appropriate place for the query. However, using Aspose.Pdf for .net you can easily change text of the link. Please check last section of following documentation link to manipulate link annotation text. Hopefully it will help you to accomplish the task.


Please feel free to contact us for any further assistance.

Best Regards,

Hi Tilal Ahmad,

Thanks for updating. I am sorry that I mentioned about itextsharp in the question.

I have gone through last section of the given link. but there it is Updating LinkAnnotation Text Color.



My requirement is I need to update all the hyperlinks and hyperlinks text in PDF document.

for this can you please provide any sample code and provide the link to download Aspose.Pdf dll(Mention Version of the dll also).



My project environment is Visual Studio 2012.



regards

ashok

Hi Ashok,


Thanks for your inquiry. Please note in mentioned section code is change text color, you may also use set Text property of TextFragment to change the text and at same link second section shows how to set link of linkAnnotaion. However, please check a sample code snippet as following.

Moreover, you may please download latest version of Aspose.Pdf for .NET from download section. To evaluate API you may request a 30 days temporary license and check license implementation documentation as well. Hopefully it will help you to accomplish the task.

Document doc = new
Document(“input.pdf”);<o:p></o:p>

// get the first link annotation from first page of document

LinkAnnotation linkAnnot = (LinkAnnotation)doc.Pages[1].Annotations[1];

if (linkAnnot.Action is GoToURIAction)

{

// Modification link: change link URI

GoToURIAction goToAction = (GoToURIAction)linkAnnot.Action;

// specify the URI for link object

goToAction.URI = "www.google.com";

// save the document with updated link

// Search the text under the annotation

TextFragmentAbsorber ta = new TextFragmentAbsorber();

Aspose.Pdf.Rectangle rect = linkAnnot.Rect;

rect.LLX -= 10;

rect.LLY -= 10;

rect.URX += 10;

rect.URY += 10;

ta.TextSearchOptions = new TextSearchOptions(rect);

ta.Visit(doc.Pages[1]);

// Change color and text.

foreach (TextFragment tf in ta.TextFragments)

{

tf.TextState.ForegroundColor = Aspose.Pdf.Color.Red;

tf.Text = "ClickHere";

}

}

doc.Save("output.pdf");

Please feel free to contact us for any further assistance.


Best Regards,

Hi Team,

Thanks for updating. It is replacing text and hyperlink. but here the issue is text is replaced with underline and with different font.



Our requirement is to replace hyperlink and hyperlink text with same font(old text font) and at the same location(if underline is there underline is required else no need of underline).



Note : If PDF document is having more than 4 hyperlinks (for ex: 20). if we execute this code in for loop we are getting following exception.

Exception : At most 4 elements (for any collection) can be viewed in evaluation mode.



Please provide the solution and License purchase details.



Regards

Ashok

Hi Ashok,


Thanks for your feedback. Please share your sample document here, we will look into it and will guide you accordingly.

Moreover, in reference to 4 element restriction exception, your are getting the exception as you are evaluating API without a valid license. Please make a request for 30 days temporary license for evaluating without any restriction. Please also check license implementation documentation.

Best Regards,