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 hyperlink of a document. For changing hyperlinks destination, you may first get URI of LinkAnnotation Action, analyze it as per your requirement and update URI to new value. Please check following code snippet to update Action URI. Hopefully it will help you in accomplishing your requirements.

// load the PDF file<o:p></o:p>

Document doc = new Document(myDir + "input.pdf");

// get the first link annotation from first page of 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 updated link

doc.Save(myDir + "LINK_Modified_output.pdf");

Please feel free to contact us for any further assistance.


Best Regards,