Reference Guide
GdPicture14 Namespace / GdPicturePDF Class / SetMeasurementUnit Method
A member of the PdfMeasurementUnit enumeration. You can select one of these: point, millimeter, centimeter, inch.
Example





In This Topic
    SetMeasurementUnit Method (GdPicturePDF)
    In This Topic
    Sets the measurement units to be used for the currently loaded PDF document. Please note that you need to create or load the PDF document properly to set the valid value, otherwise the value will remain undefined.
    Syntax
    'Declaration
     
    
    Public Sub SetMeasurementUnit( _
       ByVal UnitMode As PdfMeasurementUnit _
    ) 
    public void SetMeasurementUnit( 
       PdfMeasurementUnit UnitMode
    )
    public procedure SetMeasurementUnit( 
        UnitMode: PdfMeasurementUnit
    ); 
    public function SetMeasurementUnit( 
       UnitMode : PdfMeasurementUnit
    );
    public: void SetMeasurementUnit( 
       PdfMeasurementUnit UnitMode
    ) 
    public:
    void SetMeasurementUnit( 
       PdfMeasurementUnit UnitMode
    ) 

    Parameters

    UnitMode
    A member of the PdfMeasurementUnit enumeration. You can select one of these: point, millimeter, centimeter, inch.
    Remarks
    It is recommend to use the GetStat method to identify the specific reason for the method's failure, if any. Please ensure that you have successfully created or loaded a PDF document, otherwise the method does nothing.

    All locations and sizes in PDF document are stored in a logical value called a PDF point. 1 point is equivalent to 1/72 of an inch. Therefore the default PDF measurement units are points.

    Example
    How to find out the position of the first page's media box in millimetres and in centimetres of the currently loaded PDF document.
    Dim oGdPicturePDF As New GdPicturePDF()
    Dim message As String = "NO document IS loaded." + vbCrLf + vbCrLf
                
    'This is the incorrect usage - the values will remain undefined.
    oGdPicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
    Dim status As GdPictureStatus = oGdPicturePDF.GetStat()
    message = message + "Status for SetOrigin(PdfOrigin.PdfOriginTopLeft): " + status.ToString()
    oGdPicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitMillimeter)
    status = oGdPicturePDF.GetStat()
    message = message + vbCrLf + "Status for SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitMillimeter): " + status.ToString()
    MessageBox.Show(message, "Example: SetMeasurementUnit")
                
    'You need to load the file here.
    status = oGdPicturePDF.LoadFromFile("test.pdf", False)
    If status = GdPictureStatus.OK Then
        message = "Your pdf document IS loaded." + vbCrLf + vbCrLf
                
        status = oGdPicturePDF.SelectPage(1)
        If status = GdPictureStatus.OK Then
            'This is the correct usage.
            oGdPicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
            If oGdPicturePDF.GetStat() = GdPictureStatus.OK Then
                
                oGdPicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitMillimeter)
                If oGdPicturePDF.GetStat() = GdPictureStatus.OK Then
                    Dim pLeft As Single = 0, pTop As Single = 0, pRight As Single = 0, pBottom As Single = 0
                    oGdPicturePDF.GetPageBox(PdfPageBox.PdfPageBoxMediaBox, pLeft, pTop, pRight, pBottom)
                    message = message + "First page mediabox : (" + pLeft.ToString() + " * " + pTop.ToString() + ")-(" + pRight.ToString() + "*" + pBottom.ToString() + ") millimetres." + vbCrLf + vbCrLf
                End If
                
                oGdPicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter)
                If oGdPicturePDF.GetStat() = GdPictureStatus.OK Then
                    Dim pLeft As Single = 0, pTop As Single = 0, pRight As Single = 0, pBottom As Single = 0
                    oGdPicturePDF.GetPageBox(PdfPageBox.PdfPageBoxMediaBox, pLeft, pTop, pRight, pBottom)
                    message = message + "First page mediabox : (" + pLeft.ToString() + " * " + pTop.ToString() + ")-(" + pRight.ToString() + "*" + pBottom.ToString() + ") centimetres."
                    MessageBox.Show(message, "Example: SetMeasurementUnit")
                End If
            End If
        Else
            MessageBox.Show("This PDF has no pages.", "Example: SetMeasurementUnit")
        End If
    Else
        MessageBox.Show("The file can't be loaded. Status: " + status.ToString(), "Example: SetMeasurementUnit")
    End If
    oGdPicturePDF.Dispose()
    GdPicturePDF oGdPicturePDF = new GdPicturePDF();
    string message = "NO document IS loaded.\n\n";
                
    //This is the incorrect usage - the values will remain undefined.
    oGdPicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft);
    GdPictureStatus status = oGdPicturePDF.GetStat();
    message = message + "Status for SetOrigin(PdfOrigin.PdfOriginTopLeft): " + status.ToString();
    oGdPicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitMillimeter);
    status = oGdPicturePDF.GetStat();
    message = message + "\nStatus for SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitMillimeter): " + status.ToString();
    MessageBox.Show(message, "Example: SetMeasurementUnit");
                
    //You need to load the file here.
    status = oGdPicturePDF.LoadFromFile("test.pdf", false);
    if (status == GdPictureStatus.OK)
    {
        message = "Your pdf document IS loaded.\n\n";
                
        status = oGdPicturePDF.SelectPage(1);
        if (status == GdPictureStatus.OK)
        {
            //This is the correct usage.
            oGdPicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft);
            if (oGdPicturePDF.GetStat() == GdPictureStatus.OK)
            {
                
                oGdPicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitMillimeter);
                if (oGdPicturePDF.GetStat() == GdPictureStatus.OK)
                {
                    float pLeft = 0, pTop = 0, pRight = 0, pBottom = 0;
                    oGdPicturePDF.GetPageBox(PdfPageBox.PdfPageBoxMediaBox, ref pLeft, ref pTop, ref pRight, ref pBottom);
                    message = message + "First page mediabox : (" + pLeft.ToString() + " * " + pTop.ToString() + ")-(" + pRight.ToString() + "*" + pBottom.ToString() + ") millimetres.\n\n";
                }
                
                oGdPicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter);
                if (oGdPicturePDF.GetStat() == GdPictureStatus.OK)
                {
                    float pLeft = 0, pTop = 0, pRight = 0, pBottom = 0;
                    oGdPicturePDF.GetPageBox(PdfPageBox.PdfPageBoxMediaBox, ref pLeft, ref pTop, ref pRight, ref pBottom);
                    message = message + "First page mediabox : (" + pLeft.ToString() + " * " + pTop.ToString() + ")-(" + pRight.ToString() + "*" + pBottom.ToString() + ") centimetres.";
                    MessageBox.Show(message, "Example: SetMeasurementUnit");
                }
            }
        }
        else
        {
            MessageBox.Show("This PDF has no pages.", "Example: SetMeasurementUnit");
        }
    }
    else
    {
        MessageBox.Show("The file can't be loaded. Status: " + status.ToString(), "Example: SetMeasurementUnit");
    }
    oGdPicturePDF.Dispose();
    See Also