GdPicture.NET.14.API
GdPicture14 Namespace / GdPicturePDF Class / GetPageImageCoordinates Method
The 0-based index of the image within the current page. It must be a value from 0 to GdPicturePDF.GetPageImageCount-1.
Output parameter. The horizontal (X) coordinate of the top left point, where the image is located. The returned value is expressed in the current units specified by the SetMeasurementUnit method with respect to the currently defined origin.
Output parameter. The vertical (Y) coordinate of the top left point, where the image is located. The returned value is expressed in the current units specified by the SetMeasurementUnit method with respect to the currently defined origin.
Output parameter. The horizontal (X) coordinate of the top right point, where the image is located. The returned value is expressed in the current units specified by the SetMeasurementUnit method with respect to the currently defined origin.
Output parameter. The vertical (Y) coordinate of the top right point, where the image is located. The returned value is expressed in the current units specified by the SetMeasurementUnit method with respect to the currently defined origin.
Output parameter. The horizontal (X) coordinate of the bottom left point, where the image is located. The returned value is expressed in the current units specified by the SetMeasurementUnit method with respect to the currently defined origin.
Output parameter. The vertical (Y) coordinate of the bottom left point, where the image is located. The returned value is expressed in the current units specified by the SetMeasurementUnit method with respect to the currently defined origin.
Example





In This Topic
GetPageImageCoordinates Method (GdPicturePDF)
In This Topic
Returns the coordinates, related to the current page, of an image, specified by its index within the currently selected page of the loaded PDF document.

The coordinates are expressed in the currently defined units in the PDF document with respect to the currently defined origin, related to the actual page. You can use the GdPicturePDF.SetMeasurementUnit method to reset the units and the GdPicturePDF.SetOrigin method to reset the origin's location according to your preference.

Syntax
'Declaration
 
Public Function GetPageImageCoordinates( _
   ByVal ImageIdx As Integer, _
   ByRef x0 As Single, _
   ByRef y0 As Single, _
   ByRef x1 As Single, _
   ByRef y1 As Single, _
   ByRef x2 As Single, _
   ByRef y2 As Single _
) As GdPictureStatus
public GdPictureStatus GetPageImageCoordinates( 
   int ImageIdx,
   ref float x0,
   ref float y0,
   ref float x1,
   ref float y1,
   ref float x2,
   ref float y2
)
public function GetPageImageCoordinates( 
    ImageIdx: Integer;
   var  x0: Single;
   var  y0: Single;
   var  x1: Single;
   var  y1: Single;
   var  x2: Single;
   var  y2: Single
): GdPictureStatus; 
public function GetPageImageCoordinates( 
   ImageIdx : int,
   x0 : float,
   y0 : float,
   x1 : float,
   y1 : float,
   x2 : float,
   y2 : float
) : GdPictureStatus;
public: GdPictureStatus GetPageImageCoordinates( 
   int ImageIdx,
   ref float x0,
   ref float y0,
   ref float x1,
   ref float y1,
   ref float x2,
   ref float y2
) 
public:
GdPictureStatus GetPageImageCoordinates( 
   int ImageIdx,
   float% x0,
   float% y0,
   float% x1,
   float% y1,
   float% x2,
   float% y2
) 

Parameters

ImageIdx
The 0-based index of the image within the current page. It must be a value from 0 to GdPicturePDF.GetPageImageCount-1.
x0
Output parameter. The horizontal (X) coordinate of the top left point, where the image is located. The returned value is expressed in the current units specified by the SetMeasurementUnit method with respect to the currently defined origin.
y0
Output parameter. The vertical (Y) coordinate of the top left point, where the image is located. The returned value is expressed in the current units specified by the SetMeasurementUnit method with respect to the currently defined origin.
x1
Output parameter. The horizontal (X) coordinate of the top right point, where the image is located. The returned value is expressed in the current units specified by the SetMeasurementUnit method with respect to the currently defined origin.
y1
Output parameter. The vertical (Y) coordinate of the top right point, where the image is located. The returned value is expressed in the current units specified by the SetMeasurementUnit method with respect to the currently defined origin.
x2
Output parameter. The horizontal (X) coordinate of the bottom left point, where the image is located. The returned value is expressed in the current units specified by the SetMeasurementUnit method with respect to the currently defined origin.
y2
Output parameter. The vertical (Y) coordinate of the bottom left point, where the image is located. The returned value is expressed in the current units specified by the SetMeasurementUnit method with respect to the currently defined origin.

Return Value

A member of the GdPictureStatus enumeration. If the method has been successfully followed, then the return value is GdPictureStatus.OK.

We strongly recommend always checking this status first.

Remarks
This method is only allowed for use with non-encrypted documents.

Be aware that the values of coordinates and dimensions are expressed in the current units defined by the GdPicturePDF.SetMeasurementUnit method according to the current coordinate space defined by the GdPicturePDF.SetOrigin method.

Example
How to find out the coordinates of all images contained within the PDF document.
Dim caption As String = "Example: GetPageImageCoordinates"
Dim gdpicturePDF As New GdPicturePDF()
If gdpicturePDF.LoadFromFile("test.pdf", False) = GdPictureStatus.OK Then
    gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
    Dim message As String = ""
    Dim imageCount As Integer = 0
    Dim x0 As Single = 0, y0 As Single = 0, x1 As Single = 0, y1 As Single = 0, x2 As Single = 0, y2 As Single = 0
    Dim pageCount As Integer = gdpicturePDF.GetPageCount()
    Dim status As GdPictureStatus = gdpicturePDF.GetStat()
    If (status = GdPictureStatus.OK) AndAlso (pageCount > 0) Then
        For i As Integer = 1 To pageCount
            If gdpicturePDF.SelectPage(i) = GdPictureStatus.OK Then
                message = message + "Page nr." + i.ToString() + ":" + vbCrLf
                imageCount = gdpicturePDF.GetPageImageCount()
                status = gdpicturePDF.GetStat()
                If (status = GdPictureStatus.OK) AndAlso (imageCount > 0) Then
                    For j As Integer = 0 To imageCount - 1
                        status = gdpicturePDF.GetPageImageCoordinates(j, x0, y0, x1, y1, x2, y2)
                        If status = GdPictureStatus.OK Then
                            message = message + "The image indexed as " + j.ToString() + " has the following coordinates:" + vbCrLf +
                                "TL[" + x0.ToString() + "," + y0.ToString() + "], TR[" + x1.ToString() + "," + y1.ToString() + "], BL[" + x2.ToString() + "," + y2.ToString() + "]" + vbCrLf
                        Else
                            message = message + "The GetPageImageCoordinates() method has failed for the image nr. " + j.ToString() + " with the status: " + status.ToString() + vbCrLf
                        End If
                    Next
                Else
                    If status = GdPictureStatus.OK Then
                        message = message + "This page doesn't contain any image." + vbCrLf
                    Else
                        message = message + "The GetPageImageCount() method has failed for the page nr. " + i.ToString() + " with the status: " + status.ToString() + vbCrLf
                    End If
                End If
            Else
                message = message + "The SelectPage() method has failed for the image nr. " + i.ToString() + " with the status: " + gdpicturePDF.GetStat().ToString() + vbCrLf
            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: GetPageImageCoordinates";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
if (gdpicturePDF.LoadFromFile("test.pdf", false) == GdPictureStatus.OK)
{
    gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft);
    string message = "";
    int imageCount = 0;
    float x0 = 0, y0 = 0, x1 = 0, y1 = 0, x2 = 0, y2 = 0;
    int pageCount = gdpicturePDF.GetPageCount();
    GdPictureStatus status = gdpicturePDF.GetStat();
    if ((status == GdPictureStatus.OK) && (pageCount > 0))
    {
        for (int i = 1; i <= pageCount; i++)
        {
            if (gdpicturePDF.SelectPage(i) == GdPictureStatus.OK)
            {
                message = message + "Page nr." + i.ToString() + ":\n";
                imageCount = gdpicturePDF.GetPageImageCount();
                status = gdpicturePDF.GetStat();
                if ((status == GdPictureStatus.OK) && (imageCount > 0))
                {
                    for (int j = 0; j < imageCount; j++)
                    {
                        status = gdpicturePDF.GetPageImageCoordinates(j, ref x0, ref y0, ref x1, ref y1, ref x2, ref y2);
                        if (status == GdPictureStatus.OK)
                            message = message + "The image indexed as " + j.ToString() + " has the following coordinates:\nTL[" +
                                x0.ToString() + "," + y0.ToString() + "], TR[" + x1.ToString() + "," + y1.ToString() + "], BL[" +
                                x2.ToString() + "," + y2.ToString() + "]\n";
                        else
                            message = message + "The GetPageImageCoordinates() method has failed for the image nr. " + j.ToString() + " with the status: " + status.ToString() + "\n";
                    }
                }
                else
                {
                    if (status == GdPictureStatus.OK)
                        message = message + "This page doesn't contain any image.\n";
                    else
                        message = message + "The GetPageImageCount() method has failed for the page nr. " + i.ToString() + " with the status: " + status.ToString() + "\n";
                }
            }
            else
            {
                message = message + "The SelectPage() method has failed for the image nr. " + i.ToString() + " with the status: " + gdpicturePDF.GetStat().ToString() + "\n";
            }
        }
        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