简体   繁体   English

如何查找用户点击 PDF 页面内的链接

[英]How to find user clicks on a link inside a PDF page

This is regarding UWP PDFNet Sdk.这是关于 UWP PDFNet Sdk。 I need to capture an event when a user clicks on an embedded link in a PDF document.当用户单击 PDF 文档中的嵌入式链接时,我需要捕获一个事件。 I need to capture the embedded link's data as well.我还需要捕获嵌入式链接的数据。 Any help would be appreciated.任何帮助,将不胜感激。

在此处输入图像描述

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.要捕获嵌入链接的数据,您将使用以下方法PDFViewCtrl.GetLinkAt()将返回有关 X 和 Y position 的链接的信息。

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();
                }
            }
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM