How to save and load a custom property on an annotation?

190 views
Skip to first unread message

Matt Parizeau

unread,
Jan 23, 2018, 4:33:20 PM1/23/18
to PDFTron WebViewer
Q:

How do I save and load a custom property on an annotation? I want the property to be preserved when I load the annotations from my server.

A:

You can extend the serialize and deserialize functions of Annotations.Annotation so that it adds a custom attribute to exported XFDF. For example:

var serialize = Annotations.Annotation.prototype.serialize;
Annotations.Annotation.prototype.serialize = function() {
 
var el = serialize.apply(this, arguments);
 
if (this.myCustomAttribute) {
    el
.setAttribute('attribute-name', this.myCustomAttribute);
 
}
 
return el;
};

var deserialize = Annotations.Annotation.prototype.deserialize;
Annotations.Annotation.prototype.deserialize = function(el) {
  deserialize
.apply(this, arguments);
 
this.myCustomAttribute = el.getAttribute('attribute-name');
 
return el;
};

Reply all
Reply to author
Forward
0 new messages