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

45 views
Skip to first unread message

Ryan

unread,
Dec 1, 2015, 1:41:08 PM12/1/15
to PDFTron PDFNet SDK
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

Ryan

unread,
Dec 4, 2015, 1:47:40 PM12/4/15
to PDFTron PDFNet SDK
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());


Reply all
Reply to author
Forward
0 new messages