How to check or test if an Annotation contains another annotation


Steps :

  • Draw an Annotation
  • Draw a second annotation inside the first one

how to check pragmatically that the second annotation is fully inside the first one ?

Thank you in advance.

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:



You can do that with the contains method on Rects: PDFTron WebViewer Class: Rect. Every annotation allows you to get their rect body so you can perform this comparison on each of them:

const annotList = documentViewer.getAnnotationManager().getAnnotationsList();
annotList.forEach(annotA => {
  const rectA = annotA.getRect();
  annotList.forEach(annotB => {
    if (annotA !== annotB) {
      const rectA = annotA.getRect();
      const rectB = annotB.getRect();
      if (rectA.contains(rectB)) {
        console.log('A contains B');
      } else if (rectB.contains(rectA)) {
        console.log('B contains A');
      } else {
        console.log('No collision');