On this page
Adjust Existing Measurement Annotations
For existing measurement annotations, you can reset measurement-related information such as scale, units, and precision without redrawing the annotation.
Taking the line segment measurement tool as an example, you can adjust the properties of an existing measurement annotation through the following steps:
- In the data returned by
AnnotActiveHandler
, check theType
parameter of theCPDFAnnotation
object representing the line measurement tool. If it isC_ANNOTATION_TYPE.C_ANNOTATION_LINE
, convert theCPDFAnnotation
type of the line measurement tool to aCPDFLineAnnotation
object. - Use the
IsMersured
method to determine if the object is a measurement tool. If true, call theGetDistanceMeasure
method to obtain the correspondingCPDFDistanceMeasure
object. - Retrieve the
MeasureInfo
from theCPDFDistanceMeasure
object and assign values to it. - Call the
SetMeasureInfo
,SetMeasureScale
, andUpdateAnnotMeasure
methods ofCPDFDistanceMeasure
to complete parameter updates. - Finally, call the
UpdateAp
method ofCPDFAnnotation
to update the annotation appearance, and then callargs.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;
}