How to replace a appointed hyperlink in PDF

test.pdf (82.1 KB)
Hi Aspose team,

In attached test pdf you can find two links, I want to change the first link “www.google.com” into “www.aspose.com”, and keep up the second. How do I coding about it?

Thanks,
Realdream

@mykong

Thanks for contacting support.

Please check following code snippet to replace the URI of specific link annotation inside PDF document. For your reference, I have also attached an output, generated by below code snippet.

Document pdfDocument = new Document(dataDir + "testLink.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;
        if (linkAnno.Action is GoToURIAction)
         {
           GoToURIAction goToAction = (GoToURIAction)linkAnno.Action;
           if (goToAction.URI == "http://www.google.com/")
              goToAction.URI = "http://www.aspose.com/";
         }
     }
  }
}
pdfDocument.Save(dataDir + "linktest_processed.pdf"); 

linktest_processed.pdf (82.3 KB)

In case of any further assistance, please feel free to contact us.

Your code is working fine.
Thanks a lot for your quick response.

@mykong

Thanks for your feedback.

It is good to know that suggested code snippet worked for you. Please keep using our API and in case of any further assistance, please feel free to contact us.