-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
comments on PDF files in landscape orientation are rotated and in wrong position #7631
Comments
Closing as incomplete because the requested information is not provided. |
Sorry for not providing requested information when I created this issue - I hit the wrong button. Anyway, I updated the issue with all the required information. Can you please take a look? Thanks. |
The annotation has the NoRotate flag set. |
I wonder why it's even rotated as the page itself is not rotated. Even if we would respect the |
That probably explains the issue. Thanks for looking into this. This issue is about supporting the |
Thanks for looking into it. Please let me know if you need anything from me. |
We also run into that issue. Attached an additional example file. I guess it shouldn't be that hard to fix, because a simple matrix calculation depending on the rotation and NoRotate flag should be all. All you have to do is to rotate on the upper left corner. I'm sorry for not offering a pull request but I simply have no deep knowledge in pdf.js. |
+1 |
Another test file, I created it myself: |
Are there any known workarounds for this? |
I was also running into this problem. Here's a JavaScript workaround I wrote to correct this problem: // This patch rotates PDF.js hover annotations so that they always appear upright.
// It is a workaround for this issue: https://github.com/mozilla/pdf.js/issues/7631
const rotateAnnotations = () => {
document.querySelectorAll("[data-annotation-id]").forEach((annotation) => {
const popup = annotation.querySelector(".popupWrapper");
if (!popup) { return; }
const transform = annotation.style.transform;
if (!transform) { return; }
const parts = transform.split(/[(,]/);
if (parts[0] !== "matrix" || parts.length !== 7) { return; }
let rotation = 0;
if (parts[1].trim().startsWith("-")) { rotation = 180; }
if (parts[2].trim().startsWith("-")) { rotation = 270; }
if (parts[3].trim().startsWith("-")) { rotation = 90; }
popup.style.transform = `rotate(-${rotation}deg)`;
popup.style.transformOrigin = "0";
});
};
rotateAnnotations();
PDFViewerApplication.eventBus.on("annotationlayerrendered", rotateAnnotations); I've tried to be defensive but it could break in the future if PDF.js starts using different class names in the DOM. It won't rotate the speech bubble image inside the PDF itself, but it will rotate the text that appears on hover. The final line ensures that pages loaded in dynamically after page load have the patch applied to them. |
There is a problem in pdf.js when displaying comments on documents in landscape orientation. The comment icon and popup text are shown as rotated 90 degree. Documents in portrait orientation don't have this problem.
Link to PDF file (or attach file here):
Please see the attached pdf_landscape_adobe.pdf
pdf_landscape_adobe.pdf
Configuration:
Steps to reproduce the problem:
What is the expected behavior? (add screenshot)
The comment should be displayed correctly as annotation. See screenshot
pdf_landscape_expected.png.
What went wrong? (add screenshot)
The following problems were observed. See screenshot pdf_landscape_bug.png.
Link to a viewer (if hosted on a site other than mozilla.github.io/pdf.js or as Firefox/Chrome extension):
http://mozilla.github.io/pdf.js/web/viewer.html
The text was updated successfully, but these errors were encountered: