How do I change all hyperlinks in a document to look like a web page hyperlink?

Q:

I want to find all the hyperlink annotations in a PDF, and make them have a blue underline.

A:

The following code will do this.

for (PageIterator itr = doc.GetPageIterator(); itr.HasNext(); itr.Next())
{
Page page = itr.Current();
int num_annots = page.GetNumAnnots();
for (int i=0; i<num_annots; ++i)
{
Annot annot = page.GetAnnot(i);
if (!annot.IsValid()) continue;

if(annot.GetType() == Annot::e_Link)
{
Annots::Link link(annot);
Action action = link.GetAction();
if (!action.IsValid()) continue;
if (action.GetType() == Action::e_URI)
{
link.SetBorderStyle(Annot::BorderStyle(Annot::BorderStyle::e_underline, 3));
link.SetColor(ColorPt(0, 0, 1));
link.RefreshAppearance();
}
}
}
}

To also change the text underneath the link annotation to the same color, see this post
https://groups.google.com/d/msg/pdfnet-sdk/dLcJ9aQm00g/VRFE6od1HrgJ

Q:

The annotation is not appearing updated in the viewer, instead I need to zoom in or out to make it update? How do I get this to work?

A:

If you are doing this while also viewing the document, then you need to do two additional things. You need to lock the document for read/write access (which pauses background threads that might be reading the document), and then finally notify PDFViewCtrl to refresh the affected area (since PDFViewCtrl doesn’t know what you did to the document).

pdfviewctrl.DocLock();
link.SetBorderStyle(Annot::BorderStyle(Annot::BorderStyle::e_underline, 3));
link.SetColor(ColorPt(0, 0, 1));
link.RefreshAppearance();
pdfviewctrl.DocUnlock();
pdfviewctrl.Update(link, link.GetPage().GetIndex());