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.
Taking the line segment measurement tool as an example, after configuring the measurement properties, you can set up the CPDFViewerTool
to create a distance measurement tool mode through the following steps:
- Set the tool type to annotation creation mode.
- Create a
LineMeasureParam
object (usePolyLineMeasureParam
if creating a polyline tool), which can be used to set properties for the distance measurement tool.
Here is an example code for creating the distance measurement tool:
// Initializing the CPDFViewerTool.
CPDFDocument doc = CPDFDocument.InitWithFilePath("filePath");
CPDFViewerTool tool = new CPDFViewerTool();
tool.GetCPDFViewer().InitDoc(doc);
CPDFToolManager toolManager = new CPDFToolManager(tool);
// Set the mouse mode to annotation creation mode.
toolManager.SetToolType(ToolType.CreateAnnot);
toolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_LINE);
// Create a LineMeasureParam object to set properties for the distance measurement tool.
LineMeasureParam lineMeasureParam = new LineMeasureParam();
lineMeasureParam.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_LINE;
lineMeasureParam.LineColor = new byte[] { 255, 0, 0, };
lineMeasureParam.LineWidth = 2;
lineMeasureParam.Transparency = 255;
lineMeasureParam.FontColor = new byte[] { 255, 0, 0, };
lineMeasureParam.FontName = "Arial";
lineMeasureParam.FontSize = 14;
lineMeasureParam.HeadLineType = C_LINE_TYPE.LINETYPE_ARROW;
lineMeasureParam.TailLineType = C_LINE_TYPE.LINETYPE_ARROW;
lineMeasureParam.measureInfo = new CPDFMeasureInfo
{
Unit = CPDFMeasure.CPDF_CM,
Precision = CPDFMeasure.PRECISION_VALUE_TWO,
RulerBase = 1,
RulerBaseUnit = CPDFMeasure.CPDF_CM,
RulerTranslate = 1,
RulerTranslateUnit = CPDFMeasure.CPDF_CM,
CaptionType = CPDFCaptionType.CPDF_CAPTION_LENGTH,
};
tool.GetDefaultSettingParam().SetAnnotParam(lineMeasureParam);