Setting a single annotation to readonly?

101 views
Skip to first unread message

Matt Parizeau

unread,
Jul 29, 2014, 1:00:51 PM7/29/14
to pdfnet-w...@googlegroups.com
Q:

I’ve seen that the annotation manager has a method called CanModify, that returns whether an annotation is modifiable by the user. However, I haven’t found anything to set this value to false. I did find the properties NoMove and NoResize of the Annotations. But I’d also like the user to not to be able to select the annotation and draw the control handles. Kind of the same thing as setting the mode of the annotation manager to read only, but only for certain annotations (while the rest can be modifiable).

A:

Currently there isn't an API for setting an individual annotation to read only. I think the easiest way to simulate this would be to change the annotation's author to a value that you know won't be used by anyone in the document (maybe generate a GUID?). You could add a function onto the Annotation prototype to toggle read only on the annotation like the following:

var READONLY_AUTHOR = "UnusedAuthorName";

Annotations.Annotation.prototype.SetReadonly = function(value) {
   
if (value) {
       
this.oldAuthor = this.Author;
       
this.Author = READONLY_AUTHOR;
   
} else if (this.Author === READONLY_AUTHOR) {
       
this.Author = this.oldAuthor;
   
}
};

And then call it like: myAnnot.SetReadonly(true);

This works because users are only able to modify annotations created by themselves (unless they're an admin user).
Reply all
Reply to author
Forward
0 new messages