logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

New Topic Post Reply
Options
Go to last post Go to first unread
Morrison  
#1 Posted : Thursday, June 16, 2022 9:32:54 AM(UTC)
Quote
Morrison

Rank: Newbie

Groups: Registered
Joined: 6/16/2022(UTC)
Posts: 2
Germany

Hi!

I´m trying to get a value of a link clicked in pdf.

In "PdfBeforeLinkClickedEventArgs" the "e" is not giving me enough information!

I´ve tried that so far:

Code:
Private Sub PdfViewer1_BeforeLinkClicked(sender As Object, e As Patagames.Pdf.Net.EventArguments.PdfBeforeLinkClickedEventArgs) Handles PdfViewer1.BeforeLinkClicked

        e.Cancel = True

        Dim weblink = e.WebLink
        Dim link = e.Link
        Dim pageIndex = PdfViewer1.CurrentPage.PageIndex
        Dim page As PdfPage = PdfViewer1.Document.Pages(pageIndex)

        If Not IsNothing(weblink) Then
            Debug.WriteLine("Weblink")
        End If

        If Not IsNothing(link) Then
            Dim _handle = link.Handle
             
                For Each _pair In link.Dictionary

                    'I need text written on control and destination URI

                Next

        End If
    End Sub

Edited by user Saturday, June 18, 2022 10:18:34 AM(UTC)  | Reason: Not specified

Paul Rayman  
#2 Posted : Saturday, June 18, 2022 7:52:42 PM(UTC)
Quote
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,075

Thanks: 6 times
Was thanked: 124 time(s) in 121 post(s)
Hello,

for web links PdfWebLink.UrlInfo property to get URL
for other links the Destination/Action property.

Here are еру details about actions
https://pdfium.patagames...l/WorkingSDK_Actions.htm

and Destinations
https://pdfium.patagames...kingSDK_Destinations.htm

The destination cannot be a URI, so the action is of interest to you.

Code:
public virtual void ProcessAction(PdfAction pdfAction)
{
    switch (pdfAction.ActionType)
    {
        case ActionTypes.Uri:
            var ps = new ProcessStartInfo((pdfAction as PdfUriAction).ActionUrl) { UseShellExecute = true, Verb = "open" };
            Process.Start(ps);
            break;
    }
}


Links (web links, actions, and destinations) do not contain text on their own.
They are placed above the text object (or any other object). so you need to get the bounds of the link and get the text using the GetBoundedText method.

page.Text.GetBoundedText()
Morrison  
#3 Posted : Sunday, June 26, 2022 2:06:45 PM(UTC)
Quote
Morrison

Rank: Newbie

Groups: Registered
Joined: 6/16/2022(UTC)
Posts: 2
Germany

OK, thank you!

I get Text from Link like this:

Code:
 Private Sub PdfView_BeforeLinkClicked(sender As Object, e As EventArguments.PdfBeforeLinkClickedEventArgs) Handles PdfView.BeforeLinkClicked

        Dim weblink = e.WebLink
        Dim link = e.Link
        Dim pageIndex = PdfView.CurrentPage.PageIndex
        Dim page As PdfPage = PdfView.Document.Pages(pageIndex)
        'Dim document = PdfView.Document.Handle


        If Not IsNothing(link) Then
            'Dim _handle = link.Handle
            Dim pdfLink = page.Text.GetBoundedText(link.AnnotationRect)
            If Not String.IsNullOrWhiteSpace(pdfLink) OrElse Not String.IsNullOrEmpty(pdfLink) Then

                If IsNothing(link.Destination) Then
                    Debug.WriteLine("DestinationType - Nothing")
                    Debug.WriteLine(pdfLink)
                    e.Cancel = True

                    CefSharp.WebBrowserExtensions.LoadHtml(frmWebBrowser.ChromiumWebBrowser,
                                                           frmWebBrowser.CreatePage(pdfLink))

                    tabBrowser.ShowOnlyMe()

                End If

            End If
        End If

    End Sub
Quick Reply Show Quick Reply
Users browsing this topic
New Topic Post Reply
Forum Jump  
You can post new topics in this forum.
You can reply to topics in this forum.
You can delete your posts in this forum.
You can edit your posts in this forum.
You cannot create polls in this forum.
You can vote in polls in this forum.