How to access the perimeter measurement data of the PerimeterMeasurementCreateTool created annotation via Core API

Product: WebViewer

Product Version: V8.0+

Please give a brief summary of your issue:
We would like to implement a customized annotation based on the PerimeterMeasurementCreateTool and the related annotation. We already read the API documentation PDFTron WebViewer Namespace: Core but couldn’t find a way to get the perimeter measurement data based on the created annotation.

Hi,

At the moment you can get the Perimeter measurement data from the annotation properties / methods like this:

const precision = perimeterAnnotation.Precision;
const perimeter =  perimeterAnnotation.getContents();
const scaleRation =  perimeterAnnotation.Measure.scale;

The Angle is a calculated value from the paths of the Perimeter measurement annotation:

const getAngleInRadians = (pt1, pt2, pt3) => {
    let angle;

    if (pt1 && pt2) {
      if (pt3) {
        // calculate the angle using Law of cosines
        const AB = Math.sqrt(
          Math.pow(pt2.x - pt1.x, 2) + Math.pow(pt2.y - pt1.y, 2)
        );
        const BC = Math.sqrt(
          Math.pow(pt2.x - pt3.x, 2) + Math.pow(pt2.y - pt3.y, 2)
        );
        const AC = Math.sqrt(
          Math.pow(pt3.x - pt1.x, 2) + Math.pow(pt3.y - pt1.y, 2)
        );
        angle = Math.acos((BC * BC + AB * AB - AC * AC) / (2 * BC * AB));
      } else {
        angle = Math.atan2(pt2.y - pt1.y, pt2.x - pt1.x);
        angle = Math.abs(angle);
        angle = angle > Math.PI / 2 ? Math.PI - angle : angle;
      }
    }
    return angle;
}
const path = perimeterAnnotation.getPath();
const angle = getAngleInRadians(path[path.length - 3], path[path.length - 2], path[path.length - 1]);
const angleInDegree  = ((angle / Math.PI) * 180).toFixed(4);

I can see that having an API to get measurement data is useful in some situations, and I will discuss with my colleagues about creating an API for that.

Amazing! Thank you for the quick response. :slight_smile: