Find and change hyperlinks in existing PDF document(s)?

Hi Aspose team,

my scenario is that we are moving some PDF documents from one server to other.

As there are links in PDF documents which are pointing to old server I need to create application that will go through all PDF documents and:

  1. identify list of all hyperlinks (we need this for reporting reasons)
  2. replace SearchString with ReplacementString; for example, old server name was ServerOld and new server name is ServerNew

After replacement is done I need to same PDF document.

Is this possible? I do not want to search for ServerOld and replace with ServerNew as ServerOld can be part of a text without link so I need to identify that this is is really link and if yes then to do replacement.

Thanks,
Oliver

Hi Oliver,

Thanks for your inquiry. You may get LinkAnnotation of the PDF document to list hyperlinks of a document. For changing hyperlinks’ destination, you may first get the URI of the LinkAnnotation Action, analyze it as per your requirement and update the URI to a new value. Please check the following code snippet to update Action URI. Hopefully it will help you in accomplishing your requirements.

// load the PDF file
Document doc = new Document("input.pdf");

// get the first link annotation from the first page of the document
LinkAnnotation linkAnnot = (LinkAnnotation)doc.Pages[1].Annotations[1];

// Modification link: change link URI
GoToURIAction goToAction = (GoToURIAction) linkAnnot.Action;

// specify the URI for link object
goToAction.URI = "www.aspose.com";

// save the document with the updated link
doc.Save("LINK_Modified_output.pdf");

Please feel free to contact us for any further assistance.

Best Regards,