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.
You can adjust the properties of an existing measurement annotation through the following steps:
selectAnnotation method of annotationManager to select annotations.setAnnotationStyles method of annotationManager to adjust the annotation. The parameter passed is an object, which contains the annotation properties to change, such as Precision, Scale, StrokeColor, FillColor, TextColor and Opacity. To choose whether the annotation appearance displays the perimeter, area, radius, arc length and angle, use the setMeasurementDisplayOptions method of the annotation with the keys perimeter, area, radius, arcLength and angle, and then call updateAnnotation of annotationManager. To set the measured length directly, use the setMeasuredLength method of the measurement manager (documentViewer.getMeasurementManager()) for a line, or its setMeasuredSize method for a rectangle; the value is in the unit of the annotation's scale.Taking a line segment measurement annotation and a rectangle measurement annotation (a polygon annotation with four vertices) as examples, the following is an example code for adjusting existing measurement annotations:
const measurementManager = documentViewer.getMeasurementManager();
const [annotation] = annotationManager.getPageAnnotations(1); // The first annotation on the first page.
if (annotation.Measure && annotation instanceof Annotations.LineAnnotation) {
annotationManager.selectAnnotation(annotation);
await annotationManager.setAnnotationStyles(annotation, {
Precision: 1,
Opacity: 0.5,
StrokeColor: new Annotations.Color('#2D77FA'),
TextColor: new Annotations.Color('#64BC38')
});
await measurementManager.setMeasuredLength(annotation, 3); // In the unit of the scale.
}
if (annotation.Measure && annotation instanceof Annotations.PolygonAnnotation) {
annotationManager.selectAnnotation(annotation);
await annotationManager.setAnnotationStyles(annotation, {
Precision: 0.01,
StrokeColor: new Annotations.Color('#64BC38'),
FillColor: new Annotations.Color(255, 236, 102, 0.5) // #FFEC66 with an opacity of 0.5.
});
await measurementManager.setMeasuredSize(annotation, { width: 5.45 }); // The horizontal side, in the unit of the scale.
annotation.setMeasurementDisplayOptions({ perimeter: true });
await annotationManager.updateAnnotation(annotation);
}