1

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

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
SurenSaluka
  • 1,534
  • 3
  • 18
  • 36

2 Answers2

1

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.

Derek
  • 11
  • 1
0

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();
                }
            }
        }
SurenSaluka
  • 1,534
  • 3
  • 18
  • 36