Skip to content

bug: inserting rotated pages to another document messes up link coordinates #4958

Closed

Description

@mahlzahn

Description of the bug

Copying pages togther with links from one document to another leads to wrong coordinates in the copied document, see reproducer below.

How to reproduce the bug

import pymupdf

document = pymupdf.Document()
document.new_page()
document[0].set_rotation(90)
document[0].insert_link({'kind': 2, 'from': pymupdf.Rect(10, 20, 40, 60), 'uri': 'https://example.org'})

document_copy = pymupdf.Document()
document_copy.insert_pdf(document, links=True)

print('orig:', *(l['from'] for l in document[0].get_links()))
print('copy:', *(l['from'] for l in document_copy[0].get_links()))

prints

orig: Rect(782.0, 10.0, 822.0, 40.0)
copy: Rect(802.0, 782.0, 832.0, 822.0)

PyMuPDF version

1.27.2

Operating system

Linux

Python version

3.14

Activity

  1. mahlzahn commented on Mar 30, 2026

    @mahlzahn
    Author

    Possible workaround:

    document_copy2 = pymupdf.Document()
    document_copy2.insert_pdf(document, links=False)
    for i in range(len(document)):
        document_copy2[i].set_rotation(0)
        for link in document[i].get_links():
            link['from'] = link['from'].transform(document[i].derotation_matrix)
            document_copy2[i].insert_link(link)
        document_copy2[i].set_rotation(document[i].rotation)
    print('copy2:', *(l['from'] for l in document_copy2[0].get_links()))

    But, it is probably still wrong for scaled or otherwise transformed documents.

  2. lailasaiid931-ai commented on Mar 31, 2026

    @lailasaiid931-ai
  3. julian-smith-artifex-com commented on Apr 10, 2026

    @julian-smith-artifex-com
    Collaborator

    Thanks for the report and the reproducer.

    Fixed in 962163d.

    We will keep this issue open until we've released the fix.

  4. julian-smith-artifex-com commented on Apr 24, 2026

    @julian-smith-artifex-com
    Collaborator

    Fixed in pymupdf-1.27.2.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions