Hello.
I have tried with the free hand annotation on the showcase, after uploading the document.
In our solution we have version 2.2.0 of the WebViewer and we have patched it with the latest code of function `loadPageLoop()` (inside BaseReaderControl.js) :
var pageNumber = pages[index];
var doc = me.docViewer.getDocument();
var originalDocumentRotation = (me.docViewer.getCompleteRotation(pageNumber) - me.docViewer.getRotation(pageNumber));
var pageInfo = doc.getPageInfo(pageNumber - 1);
var annotationRotationOffset = 0;
var rotation = 0;
if (orientation === me.pageOrientations.Portrait) {
annotationRotationOffset = originalDocumentRotation;
pageInfo = {
width: pageInfo.height,
height: pageInfo.width
};
} else if (orientation === me.pageOrientations.Landscape) {
rotation = 1;
annotationRotationOffset = (originalDocumentRotation + 1) % 4;
if (originalDocumentRotation !== 0) {
pageInfo = {
width: pageInfo.height,
height: pageInfo.width
};
}
} else if (orientation === me.pageOrientations.Auto) {
if (pageInfo.width > pageInfo.height) {
if (originalDocumentRotation === 0) {
rotation = 1;
annotationRotationOffset = 1;
} else {
rotation = 4 - originalDocumentRotation;
}
}
}
var zoom = me.printFactor;
doc.loadCanvasAsync(pageNumber - 1, zoom, rotation, function(canvas) {
// scale the canvas context so that annotations are drawn in the correct location
var ctx = canvas.getContext('2d');
ctx.scale(me.printFactor, me.printFactor);
// 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);
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);
And we still get the same behavior as in the showcase.
Here are some console tests I did:
var pg = 1;[readerControl.docViewer.getCompleteRotation(pg), readerControl.docViewer.getRotation(pg)]
(All the document pages have this orientation)
Everything seems OK before printing, but when you select to print from the toolbar, the preview generated has all the annotations rotated and in the wrong place (we have some custom watermarks and page numbers, plus some user free-hand annotations).
I hope this helps.
Hm... I have now tested on another document with the same rotation and this problem does not appear to happen.
I am not 100% sure what is so special with this document.
I will let you know if I find something out...