GdPicture.NET.14.API
GdPicture14 Namespace / GdPicturePDF Class / GetPageImageCount Method / GetPageImageCount() Method
Example





In This Topic
GetPageImageCount() Method
In This Topic
Returns the number of all images contained within the currently selected page of the loaded PDF document.
Syntax
'Declaration
 
Public Overloads Function GetPageImageCount() As Integer
public int GetPageImageCount()
public function GetPageImageCount(): Integer; 
public function GetPageImageCount() : int;
public: int GetPageImageCount(); 
public:
int GetPageImageCount(); 

Return Value

The number of all images included within the current 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 images contained within all pages of the PDF document.
Dim caption As String = "Example: GetPageImageCount"
Dim gdpicturePDF As New GdPicturePDF()
If gdpicturePDF.LoadFromFile("test.pdf", False) = GdPictureStatus.OK Then
    Dim pageCount As Integer = gdpicturePDF.GetPageCount()
    Dim status As GdPictureStatus = gdpicturePDF.GetStat()
    If (status = GdPictureStatus.OK) AndAlso (pageCount > 0) Then
        Dim message As String = ""
        Dim imageCount As Integer = 0
        For i As Integer = 1 To pageCount
            status = gdpicturePDF.SelectPage(i)
            If status = GdPictureStatus.OK Then
                imageCount = gdpicturePDF.GetPageImageCount()
                If status = GdPictureStatus.OK Then
                    message = message + "The page nr." + i.ToString() + " contains " + imageCount.ToString() + " images." + vbCrLf
                Else
                    message = message + "The GetPageImageCount() method has failed for the page nr. " + i.ToString() + " with the status: " + status.ToString() + vbCrLf
                End If
            Else
                MessageBox.Show("The SelectPage() method has failed for the page number " + i.ToString() + " with the status: " + status.ToString(), caption)
                Exit For
            End If
        Next
        MessageBox.Show(message, caption)
    Else
        If (status = GdPictureStatus.OK) Then
            MessageBox.Show("This file doesn't contain any page.", caption)
        Else
            MessageBox.Show("The GetPageCount() method has failed with the status: " + status.ToString(), caption)
        End If
    End If
Else
    MessageBox.Show("The file can't be loaded.", caption)
End If
gdpicturePDF.Dispose()
string caption = "Example: GetPageImageCount";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
if (gdpicturePDF.LoadFromFile("test.pdf", false) == GdPictureStatus.OK)
{
    int pageCount = gdpicturePDF.GetPageCount();
    GdPictureStatus status = gdpicturePDF.GetStat();
    if ((status == GdPictureStatus.OK) && (pageCount > 0))
    {
        string message = "";
        int imageCount = 0;
        for (int i = 1; i <= pageCount; i++)
        {
            status = gdpicturePDF.SelectPage(i);
            if (status == GdPictureStatus.OK)
            {
                imageCount = gdpicturePDF.GetPageImageCount();
                if (status == GdPictureStatus.OK)
                {
                    message = message + "The page nr." + i.ToString() + " contains " + imageCount.ToString() + " images.\n";
                }
                else
                {
                    message = message + "The GetPageImageCount() method has failed for the page nr. " + i.ToString() + " with the status: " + status.ToString() + "\n";
                }
            }
            else
            {
                MessageBox.Show("The SelectPage() method has failed for the page number " + i.ToString() + " with the status: " + status.ToString(), caption);
                break;
            }
        }
        MessageBox.Show(message, caption);
    }
    else
    {
        if (status == GdPictureStatus.OK)
            MessageBox.Show("This file doesn't contain any page.", caption);
        else
            MessageBox.Show("The GetPageCount() method has failed with the status: " + status.ToString(), caption);
    }
}
else
    MessageBox.Show("The file can't be loaded.", caption);
gdpicturePDF.Dispose();
See Also