PDF Generation Template Editor
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
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:
CPDFAnnotation object from CPDFViewerTool, 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.IsMersured method to determine if the object is a measurement tool. If true, call the GetDistanceMeasure method to obtain the corresponding CPDFDistanceMeasure object.MeasureInfo from the CPDFDistanceMeasure object and assign values to it.SetMeasureInfo, SetMeasureScale, and UpdateAnnotMeasure methods of CPDFDistanceMeasure to complete parameter updates.UpdateAp method of CPDFAnnotation to update the annotation appearance, and then call UpdateAnnotFrame method of CPDFViewer to update the drawing.Here is an example code for adjusting existing measurement annotations:
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;
}