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

page_rotation_reset does not return page to original rotation #3062

Closed
MaryiaTsalapava opened this issue Jan 18, 2024 · 4 comments
Closed

page_rotation_reset does not return page to original rotation #3062

MaryiaTsalapava opened this issue Jan 18, 2024 · 4 comments
Assignees
Labels
bug fix developed release schedule to be determined

Comments

@MaryiaTsalapava
Copy link

Description of the bug

Original document where pages were rotated is changed after running find_tables.
page_rotation_reset does not return page to original state.

How to reproduce the bug

Steps to reproduce:

  • Find tables on page, that is rotated. Page rotation is 90 degrees in the example.
  • Save current document
  • Page has changed rotation in the original document

Expected behavior:

  • Original document page is not changed after finding tables
  • page_rotation_reset returns page to original state

Actual behavior:

  • Original document page is rotated after finding tables
  • page_rotation_reset does not return page to original state
  • Looks like the rotated page is the result page from page_rotation_set0
import fitz
from fitz.table import find_tables


doc = fitz.Document("sample.pdf")
for page in doc.pages():
    for table in find_tables(page):
        for cell in table.cells:
            rect = fitz.Rect(*cell)
            highlight = page.add_rect_annot(rect)
            highlight.update()

doc.save("sample_output.pdf")

Sample document and document with changed page are attached:
sample.pdf
sample_output.pdf

PyMuPDF version

1.23.15

Operating system

Windows

Python version

3.9

@JorjMcKie JorjMcKie self-assigned this Jan 18, 2024
@JorjMcKie JorjMcKie added bug fix developed release schedule to be determined labels Jan 18, 2024
@JorjMcKie
Copy link
Collaborator

Error identified and fixed developed. Will soon be published.
If you are interested in testing the solution, use this table.py in the branch that fixes it.

BTW: to mark table cells in a rotated page, you must multiply them with page.derotation_matrix, as shown here:

import fitz

doc = fitz.Document("sample.pdf")
page = doc[0]
tabs = page.find_tables()
tab = tabs[0]
for cell in tab.cells:
    cell = fitz.Rect(cell) * page.derotation_matrix
    page.draw_rect(cell, color=(1, 0, 0))

doc.ez_save("sample_output.pdf", pretty=True)

@MaryiaTsalapava
Copy link
Author

MaryiaTsalapava commented Jan 19, 2024

Fix in table.py works, thank you!

@JorjMcKie
Copy link
Collaborator

Thank you very much for the confirmation!

@julian-smith-artifex-com
Copy link
Collaborator

Fixed in 1.23.17.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug fix developed release schedule to be determined
Projects
None yet
Development

No branches or pull requests

3 participants