How to find user clicks on a link inside a PDF page

224 views Asked by At

This is regarding UWP PDFNet Sdk. I need to capture an event when a user clicks on an embedded link in a PDF document. I need to capture the embedded link's data as well. Any help would be appreciated.

enter image description here

2

There are 2 answers

0
SurenSaluka On BEST ANSWER

Got it working with the following code. I referred to this article btw.

       private void PDFViewCtrl_PointerPressed(object sender, PointerRoutedEventArgs e)
        {
            (this.DataContext as ViewerPageViewModel).PDFViewCtrl.SetUrlExtraction(true);

            int x = (int)e.GetCurrentPoint(sender as FrameworkElement).Position.X;
            int y = (int)e.GetCurrentPoint(sender as FrameworkElement).Position.Y;

            //var linkInfo = (this.DataContext as ViewerPageViewModel).PDFViewCtrl.GetLinkAt(x, y);
            //string url = linkInfo?.GetUrl();

            var annotation = (this.DataContext as ViewerPageViewModel).PDFViewCtrl.GetAnnotAt(x, y);
            if (annotation != null)
            {
                if (annotation.GetAnnotType() == AnnotType.e_Link)
                {
                    pdftron.PDF.Annots.Link link = new pdftron.PDF.Annots.Link(annotation.GetSDFObj());
                    pdftron.PDF.Action action = link.GetAction();

                    String uri = action.GetSDFObj().Get("URI").Value().GetAsPDFText();
                }
            }
        }
0
Derek On

To capture the embedded link's data, you would use the following method PDFViewCtrl.GetLinkAt() which will return the information on the link at the X and Y position.