Expand all, Collapse all annotations

Hello, is there a way to add Expand All, Collapse all annotations feature?

Just want to clarify what do you mean by “expand/Collapse all annotations”, Do you mean by open all the comments under the comments sections?


If not, please clarify your question by providing a screenshot.

Thanks,
Oscar

Hi Oscar,
Yes, You are correct. Expand all comments and Collapse all comments.

Thanks,
Prabahar

Unfortunately, we don’t have an API to achieve this. When expanding one comment area, there are a few logics bind with it, for example, 1)Deselect other annotation, 2) Center the page to the selected annotation, 3) Set annotation read status, plus others…

If you don’t care about to keep those logics, you can try the following code:

const annotationManager = docViewer.getAnnotationManager();
// open notes panel:
instance.openElements(['notesPanel'])

// get all annotation
const annotations = annotationManager.getAnnotationsList();

// optional: filter annotations by type
// ...

// expand them all:
// https://www.pdftron.com/api/web/CoreControls.AnnotationManager.html#selectAnnotations__anchor
annotationManager.selectAnnotations(annotations);

Oscar

Hi @Oscar_Zhang , has there been any further devlopement of this method to avoid selecting all

Hello sam.t.saber,

Welcome to the PDFTron Community Forum,

Instead of using: const annotations = annotationManager.getAnnotationsList();
You could use: const annotations = annotationManager.getAnnotationsList().filter((annotation)=>{annotation instanceof Annotations.FreeText})

So instead of getting all the annotations, we are filtering for FreeText Annotations (just for example)

Best Regards,
Tyler Gordon
Web Development Support Engineer
PDFTron

Hi tgordon, thanks for the reply.

What i am getting is the right result with the following (noting the comment is selected):

  • const annotationManager = docViewer.getAnnotationManager();
  • const annotations = annotationManager.getAnnotationsList();
  • annotationManager.selectAnnotations(annotations);

but not this option…

  • const annotationManager = docViewer.getAnnotationManager();
  • const annotations = annotationManager.getAnnotationsList().filter((annotation)=>{annotation instanceof Annotations.FreeText})
  • annotationManager.selectAnnotations(annotations);

Any tips to why this could be?

Hello sam.t.saber,

Here is an updated code snippet:

instance.Core.annotationManager.getAnnotationsList().filter((annotation)=> annotation instanceof instance.Core.Annotations.FreeTextAnnotation)

There were a few syntax problems, whoops!

Best Regards,
Tyler Gordon
Web Development Support Engineer
PDFTron