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
CPDFAnnotationobject fromCPDFViewerTool, check theTypeparameter of theCPDFAnnotationobject representing the line measurement tool. If it isC_ANNOTATION_TYPE.C_ANNOTATION_LINE, convert theCPDFAnnotationtype of the line measurement tool to aCPDFLineAnnotationobject. - Use the
IsMersuredmethod to determine if the object is a measurement tool. If true, call theGetDistanceMeasuremethod to obtain the correspondingCPDFDistanceMeasureobject. - Retrieve the
MeasureInfofrom theCPDFDistanceMeasureobject and assign values to it. - Call the
SetMeasureInfo,SetMeasureScale, andUpdateAnnotMeasuremethods ofCPDFDistanceMeasureto complete parameter updates. - Finally, call the
UpdateApmethod ofCPDFAnnotationto update the annotation appearance, and then callUpdateAnnotFramemethod ofCPDFViewerto 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;
}