Example





In This Topic
GdPicture14 Namespace / GdPicturePDF Class / GetPageUserUnit Method

GetPageUserUnit Method (GdPicturePDF)

In This Topic
Returns the user space unit value defined for the currently selected page in the loaded PDF document. It is the positive number specifying the size of default user space units, in multiples of 1/72 inch. The default value is 1.

Please note that you need to create or load the PDF document properly to get the valid value, otherwise the method does nothing. At the same, the specified value only relates to the currently selected page.

Syntax
'Declaration
 
Public Function GetPageUserUnit() As Single
public float GetPageUserUnit()
public function GetPageUserUnit(): Single; 
public function GetPageUserUnit() : float;
public: float GetPageUserUnit(); 
public:
float GetPageUserUnit(); 

Return Value

The positive number defining the size of default user space units.

The GdPicturePDF.GetStat method can be subsequently used to determine if this method has been successful.

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

Just to inform you, that the default value is 1, which means the user unit is 1/72 inch. Be aware, that the minimum allowed value is 1, the maximum allowed value is not restricted by the toolkit. For further assistance, please refer to the PDF Reference, Section "Page Objects".

Example
How to find out the current page size dimensions with the help of user space unit value.
Dim caption As String = "Example: GetPageUserUnit"
Dim gdpicturePDF As GdPicturePDF = New GdPicturePDF()
If gdpicturePDF.LoadFromFile("test.pdf", False) = GdPictureStatus.OK Then
    Dim message As String = ""
    gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitPoint)
    'Be sure you have selected the proper page.
    gdpicturePDF.SelectPage(1)
    Dim userUnits As Single = gdpicturePDF.GetPageUserUnit()
    If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
        message += "Page User Units: " + userUnits.ToString()
        Dim pageHeight As Single = gdpicturePDF.GetPageHeight()
        If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
            Dim pageWidth As Single = gdpicturePDF.GetPageWidth()
            If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
                Dim currentPageHeight As Single = pageHeight * userUnits * 1 / 72
                Dim currentPageWidth As Single = pageWidth * userUnits * 1 / 72
                message += vbCrLf + "Current page dimensions in inches:"
                message += vbCrLf + "page height = " + currentPageHeight + vbCrLf + "page width = " + currentPageWidth
            Else
                message += vbCrLf + "The GetPageWidth() method has failed with the status: " + gdpicturePDF.GetStat().ToString()
            End If
        Else
            message += vbCrLf + "The GetPageHeight() method has failed with the status: " + gdpicturePDF.GetStat().ToString()
        End If
    Else
        message += "The GetPageUserUnit() method has failed with the status: " + gdpicturePDF.GetStat().ToString()
    End If
    MessageBox.Show(message, caption)
Else
    MessageBox.Show("The file can't be loaded.", caption)
End If
gdpicturePDF.Dispose()
string caption = "Example: GetPageUserUnit";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
if (gdpicturePDF.LoadFromFile("test.pdf", false) == GdPictureStatus.OK)
{
    string message = "";
    gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitPoint);
    //Be sure you have selected the proper page.
    gdpicturePDF.SelectPage(1);
    float userUnits = gdpicturePDF.GetPageUserUnit();
    if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
    {
        message += "Page User Units: " + userUnits.ToString();
        float pageHeight = gdpicturePDF.GetPageHeight();
        if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
        {
            float pageWidth = gdpicturePDF.GetPageWidth();
            if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
            {
                float currentPageHeight = pageHeight * userUnits * 1 / 72;
                float currentPageWidth = pageWidth * userUnits * 1 / 72;
                message += "\nCurrent page dimensions in inches:\npage height = " + currentPageHeight + "\npage width = " + currentPageWidth;
            }
            else
                message += "\nThe GetPageWidth() method has failed with the status: " + gdpicturePDF.GetStat().ToString();
        }
        else
            message += "\nThe GetPageHeight() method has failed with the status: " + gdpicturePDF.GetStat().ToString();
    }
    else
        message += "The GetPageUserUnit() method has failed with the status: " + gdpicturePDF.GetStat().ToString();
    MessageBox.Show(message, caption);
}
else
    MessageBox.Show("The file can't be loaded.", caption);
gdpicturePDF.Dispose();
See Also