Skip to content

Adjust Existing Measurement Annotations

For existing measurement annotations, you can reset measurement-related information such as scale, units, and precision without redrawing the annotation.

Adjust Existing Measurement Annotations

Taking the line segment measurement tool as an example, you can adjust the properties of an existing measurement annotation through the following steps:

  1. In the data returned by AnnotActiveHandler, check the Type parameter of the CPDFAnnotation object representing the line measurement tool. If it is C_ANNOTATION_TYPE.C_ANNOTATION_LINE, convert the CPDFAnnotation type of the line measurement tool to a CPDFLineAnnotation object.
  2. Use the IsMersured method to determine if the object is a measurement tool. If true, call the GetDistanceMeasure method to obtain the corresponding CPDFDistanceMeasure object.
  3. Retrieve the MeasureInfo from the CPDFDistanceMeasure object and assign values to it.
  4. Call the SetMeasureInfo, SetMeasureScale, and UpdateAnnotMeasure methods of CPDFDistanceMeasure to complete parameter updates.
  5. Finally, call the UpdateAp method of CPDFAnnotation to update the annotation appearance, and then call args.Draw to update the drawing.

Here is an example code for adjusting existing measurement annotations:

C#
// args is the object passed by AnnotCommandHandler

CPDFAnnotation pdfAnnot = args.GetPDFAnnot();
switch (pdfAnnot.Type)
{
    case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
    {
        // Convert CPDFAnnotation type of the line measurement tool to CPDFLineAnnotation object.
        CPDFLineAnnotation lineAnnot = (CPDFLineAnnotation)pdfAnnot;
        // Check if the object is a measurement tool.
        if (lineAnnot.IsMersured())
        {
            // Get the CPDFDistanceMeasure object corresponding to the annotation.
            CPDFDistanceMeasure lineMeasure = lineAnnot.GetDistanceMeasure();

            // Set new measurement-related properties.
            CPDFMeasureInfo measureInfo = lineMeasure.MeasureInfo;
            measureInfo.Precision = MeasureSetting.GetMeasureSavePrecision();
            measureInfo.RulerBase = (float)MeasureSetting.RulerBase;
            measureInfo.RulerBaseUnit = MeasureSetting.RulerBaseUnit;
            measureInfo.RulerTranslate = (float)MeasureSetting.RulerTranslate;
            measureInfo.RulerTranslateUnit = MeasureSetting.RulerTranslateUnit;

            // Complete parameter updates.
            lineMeasure.SetMeasureInfo(measureInfo);
            lineMeasure.SetMeasureScale(
                measureInfo.RulerBase,
                measureInfo.RulerBaseUnit,
                measureInfo.RulerTranslate,
                measureInfo.RulerTranslateUnit);
            lineMeasure.UpdateAnnotMeasure();

            // Update annotation appearance.
            lineAnnot.UpdateAp();

            // Update drawing.
            args.Draw();
        }
    }
    break;
}