var CustomSelectionModel = function(annotation, canModify) {
Annotations.SelectionModel.call(this, annotation, canModify);
};
CustomSelectionModel.prototype = $.extend(true, new Annotations.BoxSelectionModel(), {
drawSelectionOutline: function() {}
});
window.CustomWatermark = function() {
Annotations.MarkupAnnotation.call(this);
this.Subject = 'Watermark';
};
window.CustomWatermark.prototype = $.extend(new Annotations.MarkupAnnotation(), {
elementName: 'watermark',
draw: function(ctx) {
ctx.translate(this.X, this.Y);
ctx.rotate(-Math.PI / 4);
ctx.font = '30px Arial';
ctx.textBaseline = 'top';
ctx.textAlign = 'center';
ctx.fillStyle = '#0000FF';
ctx.fillText('Watermark', 0, 0);
},
selectionModel: CustomSelectionModel
});
function addWatermarkToPage(am, pageInfo, pageIndex) {
var watermark = new window.CustomWatermark();
watermark.X = pageInfo.width / 2;
watermark.Y = pageInfo.height / 2;
watermark.PageNumber = pageIndex + 1;
am.addAnnotation(watermark);
}
var annotsHidden = false;
$(document).on('viewerLoaded', function() {
var docViewer = readerControl.docViewer;
window.CoreControls.AnnotationManager.prototype.toggleAnnotations = function() {
annotsHidden = !annotsHidden;
var annotList = this.getAnnotationsList();
annotList.forEach(function(annot) {
if (!(annot instanceof window.CustomWatermark)) {
annot.Hidden = annotsHidden;
}
});
var displayMode = docViewer.getDisplayModeManager().getDisplayMode();
var visiblePages = displayMode.getVisiblePages();
for (var i = 0; i < visiblePages.length; i++) {
this.drawAnnotations(visiblePages[i] + 1);
docViewer.drawSelection(visiblePages[i] + 1);
}
this.trigger('annotationToggled', [annotsHidden, annotList, this.getUseFilter()]);
};
});
$(document).on('documentLoaded', function() {
var am = readerControl.docViewer.getAnnotationManager();
var doc = readerControl.docViewer.getDocument();
var numPages = doc.getPageCount();
for (var i = 0; i < numPages; ++i) {
addWatermarkToPage(am, doc.getPageInfo(i), i);
}
});
if (annotation instanceof window.CustomWatermark) {
continue;
}
if (!(annotation instanceof Annotations.FreeTextAnnotation || annotation instanceof window.CustomWatermark))
if (annotation instanceof window.CustomWatermark) {
continue;
}
if (action === "selected") {
annotations.filter(function(annot) {
return annot instanceof window.CustomWatermark;
}).forEach(function(annot) {
annotManager.deselectAnnotation(annot);
});
}