Problem with hiding annotation

94 views
Skip to first unread message

Gowtham Lcs

unread,
Mar 19, 2018, 12:55:50 PM3/19/18
to PDFTron WebViewer
Hi Team,

Please imagine the below scenario.

1. Annotate a document(Example: draw an arrow) and name it as "A.doc".
2. Download "A.doc" and upload it as a new document and name it as "B.doc".
3. Annotate "B.doc"(Example: Highlight a text) which already has annotation present in "A.doc"(arrow in this case).
4. So, the document now contains arrow and highlight. Now hide the annotation of "B.doc".

Expected:
Only annotation drawn in "B.doc"(highlight) should be hidden. Arrow should not be hidden.

Actual:
All the annotations present in the doc is hidden(both arrow and highlight).

Please help me on this issue.

Thanks,
Gowtham C

Matt Parizeau

unread,
Mar 20, 2018, 1:40:51 PM3/20/18
to PDFTron WebViewer
Hi Gowtham,

What function are you calling to hide the annotations? The hideAnnotation or hideAnnotations functions on AnnotationManager take an annotation or an array of annotations as parameters and will hide all of the specified annotations. So when you call either of these functions just pass in the specific annotations that you want to hide.

From your description it sounds like B.doc contains both the arrow and the highlight so if you were just hiding everything in the document then I would expect both annotations to be hidden. If you want to hide only new (for some definition of new) annotations then you'll need to include some logic to detect this. This might be accomplished by adding a custom XFDF attribute or storing metadata about each annotation on your server separately but it depends on what you actually want to do.

Matt Parizeau
Software Developer
PDFTron Systems Inc.

Gowtham Lcs

unread,
Mar 21, 2018, 6:03:05 PM3/21/18
to PDFTron WebViewer
Hi Matt,

I am hiding by using toggleAnnotations(). Can you tell me the logic to hide only the newer annotation?

Matt Parizeau

unread,
Mar 22, 2018, 2:19:44 PM3/22/18
to PDFTron WebViewer
Hi Gowtham,

The toggleAnnotations function will hide/show every annotation in the document so if you want to hide particular annotations you'll need to use the hideAnnotations function on AnnotationManager.

I'm not exactly sure what logic you want for determining which "document" an annotation is a part of. You may want to listen to the annotationChanged event and check the imported property on the event object so that you can flag annotations as originally existing in the document, and ignoring any annotations that already have a flag set. Then any new annotations will have the flag set to a different value for the second document.

This post shows how to save and load a custom property on an annotation: https://groups.google.com/d/msg/pdfnet-webviewer/lptUPUcV80c/1NUgYZ_8AwAJ

Here is the code to set the custom attribute when an annotation changes:
$(document).on('viewerLoaded', function(e) {
 
var annotManager = readerControl.docViewer.getAnnotationManager();
  annotManager
.on('annotationChanged', function(e, annotations) {
   
if (e.imported) {
     
// imported annotations will be part of doc A unless they already have the attribute set
      annotations
.forEach(function(annot) {
       
if (!annot.myCustomAttribute) {
          annot
.myCustomAttribute = 'docA';
       
}
     
});
   
} else {
     
// non-imported annotations created should be part of doc B unless they already have the attribute set
      annotations
.forEach(function(annot) {
       
if (!annot.myCustomAttribute) {
          annot
.myCustomAttribute = 'docB';
       
}
     
});
   
}
 
});
});


Here is the code to hide all doc B annotations:

var docBAnnotations = annotManager.getAnnotationsList().filter(function(annot) {
 
return annot.myCustomAttribute === 'docB';
});
annotManager
.hideAnnotations(docBAnnotations);

Matt Parizeau
Software Developer
PDFTron Systems Inc.

Gowtham Lcs

unread,
Mar 26, 2018, 1:56:09 PM3/26/18
to PDFTron WebViewer
Hi Matt, 

I have tried your solution, but it doesn't work as expected. The custom attribute of the specific annotation is removed, hence the code you have given doesn't probably work. Please find the attached file for your reference.
Unimported(but changed).JPG
Unimported.JPG

Matt Parizeau

unread,
Mar 27, 2018, 6:44:40 PM3/27/18
to PDFTron WebViewer
Hi Gowtham,

Can you clarify in which case you don't see the custom attribute being added to the annotation? In theory the code that was provided should cover each case where the changed annotations were imported or not.

Are there a specific set of steps I could use to reproduce the issue?

Matt Parizeau
Software Developer
PDFTron Systems Inc.

Gowtham Lcs

unread,
Mar 28, 2018, 12:09:11 PM3/28/18
to PDFTron WebViewer
Hi Matt,

This issue can be reproduced when editing annotations and saving it. It is reproduced while calling loadDocument() in WebViewer.js. In that case, "annotationChanged" event is triggered and the object of those annotations are modified.

Regards,
Gowtham C

Matt Parizeau

unread,
Mar 29, 2018, 3:28:19 PM3/29/18
to PDFTron WebViewer
Hi Gowtham,

Did you also include the code to serialize and deserialize the custom attribute as mentioned in my previous message "This post shows how to save and load a custom property on an annotation: https://groups.google.com/d/msg/pdfnet-webviewer/lptUPUcV80c/1NUgYZ_8AwAJ"?

When I add all of this code to a config file then load a document it correctly adds "docA" to annotations that are imported and any new annotations that I create get "docB". If I save the annotations and reload the document then the imported annotations maintain their custom attribute values and new ones get "docB".

If you could provide more information about the exact steps you are taking and at which point you are having an issue this would be very helpful. If you could provide a small HTML and JavaScript sample demonstrating the issue that would also be helpful.

Matt Parizeau
Software Developer
PDFTron Systems Inc.

Gowtham Lcs

unread,
Apr 2, 2018, 1:34:15 PM4/2/18
to PDFTron WebViewer
Hi Matt,

Thank you so much. This really works. Thanks for your patience in helping me with this issue. Thank you once again.

Regards,
Gowtham C
Reply all
Reply to author
Forward
0 new messages