Reference Guide
GdPicture14 Namespace / GdPicturePDF Class / GetPageLinksCount Method
Example





In This Topic
    GetPageLinksCount Method (GdPicturePDF)
    In This Topic
    Returns the number of links (link objects) stored within the currently selected page of the loaded PDF document.
    Syntax
    'Declaration
     
    
    Public Function GetPageLinksCount() As Integer
    public int GetPageLinksCount()
    public function GetPageLinksCount(): Integer; 
    public function GetPageLinksCount() : int;
    public: int GetPageLinksCount(); 
    public:
    int GetPageLinksCount(); 

    Return Value

    The number of links embedded within the currently selected page. Please always use the GetStat method to determine if this method has been successful.
    Remarks
    Please note that this method is only allowed for use with non-encrypted documents.

    It is recommend to use the GetStat method to identify the specific reason for the method's failure, if any.

    Example
    How to find out the number of all links stored in the PDF document. This example shows you the number of links embedded on every page separately.
    Dim caption As String = "Example: GetPageLinksCount"
    Dim oGdPicturePDF As New GdPicturePDF()
    Dim status As GdPictureStatus = oGdPicturePDF.LoadFromFile("links.pdf", False)
    If status = GdPictureStatus.OK Then
        Dim totalLinksCount As Integer = 0
        Dim pagesCount As Integer = oGdPicturePDF.GetPageCount()
        If (oGdPicturePDF.GetStat() = GdPictureStatus.OK) AndAlso (pagesCount > 0) Then
            Dim linksPerPages As String = ""
            For i As Integer = 1 To pagesCount
                linksPerPages = linksPerPages + "Page Nr." + i.ToString()
                status = oGdPicturePDF.SelectPage(i)
                If status = GdPictureStatus.OK Then
                    Dim linksCount As Integer = oGdPicturePDF.GetPageLinksCount()
                    If oGdPicturePDF.GetStat() = GdPictureStatus.OK Then
                        If linksCount = 0 Then
                            linksPerPages = linksPerPages + " has no links." + vbCrLf
                        Else
                            linksPerPages = linksPerPages + " has " + linksCount.ToString() + " links." + vbCrLf
                            totalLinksCount = totalLinksCount + linksCount
                        End If
                    Else
                        linksPerPages = linksPerPages + " has failed to find links. The reason: " + status.ToString() + vbCrLf
                    End If
                Else
                    linksPerPages = linksPerPages + " has failed to select." + vbCrLf
                End If
            Next
            MessageBox.Show("This PDF document contains " + totalLinksCount.ToString() + " links." + vbCrLf + linksPerPages, caption)
        Else
            MessageBox.Show("The file has failed to load pages.", caption)
        End If
    Else
        MessageBox.Show("The file can't be loaded.", caption)
    End If
    oGdPicturePDF.Dispose()
    string caption = "Example: GetPageLinksCount";
    GdPicturePDF oGdPicturePDF = new GdPicturePDF();
    GdPictureStatus status = oGdPicturePDF.LoadFromFile("links.pdf", false);
    if (status == GdPictureStatus.OK)
    {
        int totalLinksCount = 0;
        int pagesCount = oGdPicturePDF.GetPageCount();
        if ((oGdPicturePDF.GetStat() == GdPictureStatus.OK) && (pagesCount > 0))
        {
            string linksPerPages = "";
            for (int i = 1; i <= pagesCount; i++)
            {
                linksPerPages = linksPerPages + "Page Nr." + i.ToString();
                status = oGdPicturePDF.SelectPage(i);
                if (status == GdPictureStatus.OK)
                {
                    int linksCount = oGdPicturePDF.GetPageLinksCount();
                    if (oGdPicturePDF.GetStat() == GdPictureStatus.OK)
                    {
                        if (linksCount == 0)
                            linksPerPages = linksPerPages + " has no links.\n";
                        else
                        {
                            linksPerPages = linksPerPages + " has " + linksCount.ToString() + " links.\n";
                            totalLinksCount = totalLinksCount + linksCount;
                        }
                    }
                    else
                    {
                        linksPerPages = linksPerPages + " has failed to find links. The reason: " + status.ToString() + "\n";
                    }
                }
                else
                {
                    linksPerPages = linksPerPages + " has failed to select.\n";
                }
            }
            MessageBox.Show("This PDF document contains " + totalLinksCount.ToString() + " links.\n" + linksPerPages, caption);
        }
        else
        {
            MessageBox.Show("The file has failed to load pages.", caption);
        }
    }
    else
    {
        MessageBox.Show("The file can't be loaded.", caption);
    }
    oGdPicturePDF.Dispose();
    See Also