GdPicture.NET.14.API
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. The GdPicturePDF.GetStat method can be subsequently used to determine if this method has been successful.
Remarks
This method is only allowed for use with non-encrypted documents.

It is recommend to use the GdPicturePDF.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 gdpicturePDF As New GdPicturePDF()
Dim status As GdPictureStatus = gdpicturePDF.LoadFromFile("links.pdf", False)
If status = GdPictureStatus.OK Then
    Dim totalLinksCount As Integer = 0
    Dim pagesCount As Integer = gdpicturePDF.GetPageCount()
    If (gdpicturePDF.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 = gdpicturePDF.SelectPage(i)
            If status = GdPictureStatus.OK Then
                Dim linksCount As Integer = gdpicturePDF.GetPageLinksCount()
                If gdpicturePDF.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
gdpicturePDF.Dispose()
string caption = "Example: GetPageLinksCount";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
GdPictureStatus status = gdpicturePDF.LoadFromFile("links.pdf", false);
if (status == GdPictureStatus.OK)
{
    int totalLinksCount = 0;
    int pagesCount = gdpicturePDF.GetPageCount();
    if ((gdpicturePDF.GetStat() == GdPictureStatus.OK) && (pagesCount > 0))
    {
        string linksPerPages = "";
        for (int i = 1; i <= pagesCount; i++)
        {
            linksPerPages = linksPerPages + "Page Nr." + i.ToString();
            status = gdpicturePDF.SelectPage(i);
            if (status == GdPictureStatus.OK)
            {
                int linksCount = gdpicturePDF.GetPageLinksCount();
                if (gdpicturePDF.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);
}
gdpicturePDF.Dispose();
See Also