Can you set a flag on a annotation by Javascript

58 views
Skip to first unread message

Tonny Vildevall

unread,
Aug 2, 2016, 1:26:52 PM8/2/16
to PDFTron WebViewer
Hi 
Using Webviewer, is there a way to set a flag on (e_no_zoom) on an annotation?

We want the user to pinpoint a part of the document by doubleclick and so far all i is well. Upon double click we create a new stamp annotation and adds it to the drawing but we dont know how to add this flag to the annotation. 

//Tonny

Matt Parizeau

unread,
Aug 2, 2016, 9:14:09 PM8/2/16
to PDFTron WebViewer
Hi Tonny,

Currently the NoZoom flag exists on annotations in WebViewer but it isn't properly implemented for annotations other than the sticky note annotation.

To work around this for now you could add the following customizations to a config file.

var NoZoomSelectionModel = function(annotation, canModify, isSelected) {
   
Annotations.BoxSelectionModel.call(this, annotation, canModify, isSelected);
};

NoZoomSelectionModel.prototype = {
    testSelection
: function(annotation, x, y, zoom) {
       
var width = annotation.Width;
       
var height = annotation.Height;
       
if (annotation.NoZoom) {
          width
/= zoom;
          height
/= zoom;
       
}
       
var right = annotation.X + width;
       
var bottom = annotation.Y + height;
       
return (x >= annotation.X && x <= right && y >= annotation.Y && y <= bottom);
   
}
};
NoZoomSelectionModel.prototype = $.extend(true, new Annotations.BoxSelectionModel(), NoZoomSelectionModel.prototype);

var stampDraw = Annotations.StampAnnotation.prototype.draw;
Annotations.StampAnnotation.prototype.draw = function(ctx) {
   
if (this.NoZoom) {
        ctx
.translate(-this.X, -this.Y);
   
}
    stampDraw
.apply(this, arguments);
};
Annotations.StampAnnotation.prototype.selectionModel = NoZoomSelectionModel;

To set the NoZoom flag you just need to do myAnnot.NoZoom = true;

Matt Parizeau
Software Developer
PDFTron Systems Inc.
Reply all
Reply to author
Forward
0 new messages