Skip to content
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

Rotated PDF files have a scale computation issue #554

Closed
thomas-ama opened this issue Dec 20, 2019 · 0 comments
Closed

Rotated PDF files have a scale computation issue #554

thomas-ama opened this issue Dec 20, 2019 · 0 comments
Milestone

Comments

@thomas-ama
Copy link

thomas-ama commented Dec 20, 2019

- [x] Regression (a behavior that used to work and stopped working in a new release)
- [ ] Bug report -> please search issues before submitting
- [ ] Feature request
- [ ] Documentation issue or request

PR #508 introduced a regression in release 5.3.4.

A PDF file can be rotated when created/edited with a PDF tool (Adobe Reader, Preview, etc).
The rotation is stored in the PDF file as a property: /Rotate 270 e.g.

Open a PDF in a text editor to check if it has rotation.

Note: page orientation (portrait vs landscape) has nothing to do with rotation.

Before release 5.3.4
The scale was computed as follows

scale = this.getScale((page as any).getViewport({ scale: 1 }).width);

As explained here, if the rotation parameter is not defined, PDFJS uses the Rotate property defined in the PDF file.

Since release 5.3.4
The scale is computed as follows

scale = this.getScale(
  (page as any).getViewport({ scale: 1, rotation: this._rotation })
    .width
);

By default, the scale is computed assuming no rotation (this._rotation = 0).

So, if the PDF file contains a rotation of 90, 270, etc., width and height are inverted and the PDF is displayed in the viewer with a scrollbar on the x axis (if width is originally smaller than height).

This bug cannot be solved by setting the [rotation] option.

Solutions
One solution (hot fix) is not to specify rotation in the scale computation if the rotation option has not been specified by the user. However, the rotation option will still not work for PDFs that already contain a rotation.

A better solution would be to take into account the Rotate property of the PDF.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants