Update Links in PDF

The following code snippet also work with Aspose.PDF.Drawing library.

As discussed in Add Hyperlink in a PDF File, the LinkAnnotation class makes it possible to add links in a PDF file. There’s also a similar class used to get existing links from inside PDF files. Use this if you need to update an existing link. To update an existing link:

  1. Load a PDF file.
  2. Go to a specific page in the PDF file.
  3. Specify the link destination using the GoToAction object’s Destination property.
  4. The destination page is specified using the XYZExplicitDestination constructor.

The following code snippet shows you how to update a link in a PDF file and set its target to the second page of the document.

To update the hyperlink so that it points to a web address, instantiate the GoToURIAction object and pass it to the LinkAnnotation’s Action property. The following code snippet shows how to update a link in a PDF file and set its target to a web address.

The following code snippet shows how to update a link in a PDF file and set its target to another PDF file.

Update LinkAnnotation Text Color

The link annotation does not contain text. Instead, the text is placed in the contents of the page under the annotation. Therefore, to change the color of the text, replace the color of the page text instead of trying change color of the annotation. The following code snippet shows how to update the color of link annotation in a PDF file.