Skip to content

Measure Perimeter and Area

The perimeter and area measurement tool can be used to measure the perimeter and area of a polygonal region selected by the user.

Adjust Existing Measurement Annotations

After configuring the measurement properties, you can set up the CPDFViewerTool to create a perimeter and area measurement tool mode through the following steps:

  1. Set the mouse mode to annotation creation mode.
  2. Create a PolygonMeasureParam object, which can be used to set properties for the perimeter and area measurement tool.

Here is an example code for creating the perimeter and area measurement tool:

C#
// Set the tool type to annotation creation mode.
toolManager.SetToolType(ToolType.CreateAnnot);
toolManager.SetCreateAnnotType(C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON);

// Create a PolygonMeasureParam object to set properties for the perimeter and area measurement tool.
PolygonMeasureParam polygonMeasureParam = new PolygonMeasureParam();
polygonMeasureParam.CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON;
polygonMeasureParam.LineColor = new byte[] { 255, 0, 0, };
polygonMeasureParam.LineWidth = 2;
polygonMeasureParam.Transparency = 255;
polygonMeasureParam.FontColor = new byte[] { 255, 0, 0, };
polygonMeasureParam.FontName = "Arial";
polygonMeasureParam.FontSize = 14;
polygonMeasureParam.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 | CPDFCaptionType.CPDF_CAPTION_AREA,
};
tool.GetDefaultSettingParam().SetAnnotParam(polygonMeasureParam);