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:
identify list of all hyperlinks (we need this for reporting reasons)
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 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,
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.