Skip to content

Measure Distance

The distance measurement tool allows your end-users to measure the distance between two points representing objects in a planar diagram, such as houses, streets, or walls. Upon selecting this tool, users only need to click on the starting and ending points with the pointer or finger to obtain the distance between the two points.

There are two types of distance measurement tools: the line segment measurement tool and the polyline measurement tool. The line segment measurement tool measures the distance between the starting and ending points, while the polyline measurement tool measures the distance between all adjacent points during the polyline drawing process and calculates the total length.

Measure Distance

Taking the line segment measurement tool as an example, after configuring the measurement properties, you can set up the CPDFViewer to create a distance measurement tool mode through the following steps:

  1. Create a LineMeasureArgs object (use PolyLineMeasureArgs if creating a polyline tool), which can be used to set properties for the distance measurement tool.
  2. Set the mouse mode to annotation creation mode.
  3. Pass the LineMeasureArgs object for the distance measurement tool.

Here is an example code for creating the distance measurement tool:

C#
private AnnotHandlerEventArgs CreateDistanceMeasureTool()
{
    // Create a LineMeasureArgs object to set properties for the distance measurement tool.
    LineMeasureArgs lineMeasureArgs = new LineMeasureArgs();
    lineMeasureArgs.LineColor = Colors.Red;
    lineMeasureArgs.LineWidth = 2;
    lineMeasureArgs.Transparency = 1;
    lineMeasureArgs.FontColor = Colors.Red;
    lineMeasureArgs.FontName = "Arial";
    lineMeasureArgs.FontSize = 14;
    lineMeasureArgs.HeadLineType = C_LINE_TYPE.LINETYPE_ARROW;
    lineMeasureArgs.TailLineType = C_LINE_TYPE.LINETYPE_ARROW;

    // Set the mouse mode to annotation creation mode.
    pdfViewer?.SetMouseMode(MouseModes.AnnotCreate);

    // Pass the LineMeasureArgs object for the distance measurement tool.
    pdfViewer?.SetToolParam(lineMeasureArgs);
    return lineMeasureArgs;
}