doc.loadCanvasAsync(pageNumber - 1, zoom, rotation, function(canvas) {
var ctx = canvas.getContext('2d');
// transform the canvas context so that annotations are drawn in the correct location
var t = window.GetPageMatrix(zoom, annotationRotationOffset, pageInfo);
ctx.setTransform(t.m_a, t.m_b, t.m_c, t.m_d, t.m_h, t.m_v);
me.docViewer.getAnnotationManager().drawAnnotations(pageNumber, canvas);
//apply watermark
var waterMarktext = "This is sample watermark";
var lines = waterMarktext.split('<br/>');
var fontsize = 60;
ctx.textAlign = 'center';
ctx.fillStyle = "red";
ctx.globalAlpha = 0.8;
ctx.font = fontsize + 'px san-serif';
var x = canvas.width / 2;
var y = canvas.height / 2;
y = 35;
var space = 0;
//reduce font size based on canvas width
do {
fontsize--;
ctx.font = fontsize + 'px san-serif';
} while (ctx.measureText(waterMarktext).width > canvas.width / 2)
//apply water top and bottom of the document
for (var i = 0; i < lines.length; i++) {
ctx.fillText(lines[i], x, y + space);
space = space + parseInt(fontsize);
}
space = 0;
y = canvas.height - (lines.length * fontsize);
for (var i = 0; i < lines.length; i++) {
ctx.fillText(lines[i], x, y + space);
space = space + parseInt(fontsize);
}
//End
dataurl = canvas.toDataURL();
img = $('<img>')
.attr('src', dataurl)
.css({
'max-height': '100%',
'max-width': '100%'
})
.load(function() {
if (!me.preparingForPrint) {
return;
}
printDisplay.append(img);
me.fireEvent('printProgressChanged', [index + 1, pages.length]);
index++;
if (index < pages.length) {
loadPageLoop();
} else {
completeCallback(printDisplay);
window.utils.unsetCanvasMultiplier();
me.preparingForPrint = false;
}
});
if (isInline) {
img.css('display', 'block');
if (index > 0) {
img.css('page-break-after', 'always');
}
}
}, function() {}, 1);
How would I add a watermark when printing the pages?
Please help me ASAP
Thanks