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:
- Get the
CPDFAnnotation
object fromCPDFViewerTool
, 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 callUpdateAnnotFrame
method ofCPDFViewer
to update the drawing.
Here is an example code for adjusting existing measurement annotations:
C#
BaseAnnot baseAnnot = tool.GetCacheHitTestAnnot();
CPDFAnnotation annot = baseAnnot.GetAnnotData().Annot;
switch (annot.Type)
{
case C_ANNOTATION_TYPE.C_ANNOTATION_LINE:
{
// Convert CPDFAnnotation type of the line measurement tool to CPDFLineAnnotation object.
CPDFLineAnnotation lineAnnot = (CPDFLineAnnotation)annot;
// 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.
tool.GetCPDFViewer().UpdateAnnotFrame();
}
}
break;
case C_ANNOTATION_TYPE.C_ANNOTATION_POLYLINE:
case C_ANNOTATION_TYPE.C_ANNOTATION_POLYGON:
// To do.
break;
}