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

Rotate PDF fails if /Rotate is set to an IndirectObject #337

Closed
kgengler opened this issue Mar 27, 2017 · 3 comments
Closed

Rotate PDF fails if /Rotate is set to an IndirectObject #337

kgengler opened this issue Mar 27, 2017 · 3 comments
Labels
is-bug From a users perspective, this is a bug - a violation of the expected behavior with a compliant PDF needs-example-code The issue needs a minimal and complete (e.g. all imports) example showing the problem needs-pdf The issue needs a PDF file to show the problem

Comments

@kgengler
Copy link
Contributor

kgengler commented Mar 27, 2017

Some example page objects below:

This works because '/Rotate' is set to an integer value
{'/Contents': IndirectObject(5, 0), '/Rotate': 270, '/Type': '/Page', '/Resources': IndirectObject(6, 0), '/CropBox': [0, 0, 612, 792], '/Parent': IndirectObject(1, 0), '/MediaBox': [0, 0, 612, 792]}

This will work because '/Rotate' is missing and get will return the default 0 value
{'/Parent': IndirectObject(3, 0), '/Contents': IndirectObject(4, 0), '/Type': '/Page', '/Resources': IndirectObject(6, 0), '/MediaBox': [0, 0, 612, 792]}

But if you encounter a case where '/Rotate' gets set to an IndirectObject such below:
{'/Contents': IndirectObject(2, 0), '/Rotate': IndirectObject(12, 0), '/Type': '/Page', '/Resources': IndirectObject(3, 0), '/CropBox': [0, 0, 603, 751], '/Parent': IndirectObject(13, 0), '/MediaBox': [0, 0, 603, 751]}

PyPDF2 throws an exception when attempting to rotate the page.

Example Code:

pdf_reader = PyPDF2.PdfFileReader('broken.pdf')
for page_num in range(pdf_reader.numPages):
    page = pdf_reader.getPage(page_num)
    page.rotateClockwise(90)

Output:

Traceback (most recent call last):
  File "./main.py", line 26, in <module>
    page.rotateClockwise(90)
  File "~/Desktop/pypdftest/lib/python2.7/site-packages/PyPDF2/pdf.py", line 2150, in rotateClockwise
    self._rotate(angle)
  File "~/pypdftest/lib/python2.7/site-packages/PyPDF2/pdf.py", line 2166, in _rotate
    self[NameObject("/Rotate")] = NumberObject(currentAngle + angle)
TypeError: unsupported operand type(s) for +: 'IndirectObject' and 'int'
@kgengler
Copy link
Contributor Author

Opened #338

mstamy2 added a commit that referenced this issue Dec 27, 2017
Fix issue #337 - Rotate PDF fails if /Rotate is set to an IndirectObject
@MartinThoma MartinThoma added the is-bug From a users perspective, this is a bug - a violation of the expected behavior with a compliant PDF label Apr 7, 2022
@MartinThoma
Copy link
Member

Now that #338 is merged + released, can somebody check if the issue still exists?

Can somebody maybe share an example PDF + code that was showing the issue?

@MartinThoma MartinThoma added the needs-change The PR/issue cannot be handled as issue and needs to be improved label Apr 22, 2022
@MartinThoma
Copy link
Member

I believe this was fixed. Please let me know if it wasn't.

@MartinThoma MartinThoma added needs-pdf The issue needs a PDF file to show the problem needs-example-code The issue needs a minimal and complete (e.g. all imports) example showing the problem and removed needs-change The PR/issue cannot be handled as issue and needs to be improved labels Jun 26, 2022
MartinThoma pushed a commit that referenced this issue Feb 5, 2023
…object (#1602)

The setter worked. Now the getter for the `PageObject.rotation` works as well.

Fixes #337
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
is-bug From a users perspective, this is a bug - a violation of the expected behavior with a compliant PDF needs-example-code The issue needs a minimal and complete (e.g. all imports) example showing the problem needs-pdf The issue needs a PDF file to show the problem
Projects
None yet
Development

No branches or pull requests

2 participants