Unit Conversion

All dimensional properties in GemBox.Document are measured in points unit.

Utility class LengthUnitConverter can be used to convert values between various measurement units.

Following example demonstrates how to convert points to all other measurement units.

Unit Conversion Screenshot
Upload your file (Drag file here)
using System;
using System.Text;
using GemBox.Document;

class Program
{
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        DocumentModel document = DocumentModel.Load("%InputFileName%");

        StringBuilder sb = new StringBuilder();

        sb.AppendLine("Page size (width X height):");

        double width = document.Sections[0].PageSetup.PageWidth;
        double height = document.Sections[0].PageSetup.PageHeight;

        foreach (LengthUnit unit in Enum.GetValues(typeof(LengthUnit)))
        {
            sb.AppendFormat(
                "{0} X {1} {2}",
                LengthUnitConverter.Convert(width, LengthUnit.Point, unit),
                LengthUnitConverter.Convert(height, LengthUnit.Point, unit),
                unit.ToString().ToLowerInvariant());

            sb.AppendLine();
        }

        Console.WriteLine(sb.ToString());
    }
}
Imports System
Imports System.Text
Imports GemBox.Document

Module Program

    Sub Main()

        ' If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        Dim document As DocumentModel = DocumentModel.Load("%InputFileName%")

        Dim sb As New StringBuilder()

        sb.AppendLine("Page size (width X height):")

        Dim width As Double = document.Sections(0).PageSetup.PageWidth
        Dim height As Double = document.Sections(0).PageSetup.PageHeight

        For Each unit As LengthUnit In [Enum].GetValues(GetType(LengthUnit))

            sb.AppendFormat("{0} X {1} {2}",
                            LengthUnitConverter.Convert(width, LengthUnit.Point, unit),
                            LengthUnitConverter.Convert(height, LengthUnit.Point, unit),
                            unit.ToString().ToLowerInvariant())

            sb.AppendLine()

        Next

        Console.WriteLine(sb.ToString())

    End Sub

End Module

Check next example or download examples from GitHub.