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

Map mouse click/touch event position to pdf page coordinate #140

Closed
benjinus opened this issue Feb 25, 2025 · 4 comments
Closed

Map mouse click/touch event position to pdf page coordinate #140

benjinus opened this issue Feb 25, 2025 · 4 comments

Comments

@benjinus
Copy link

Is there a way to map mouse click/touch event position to pdf page coordinate?

@ccxvii
Copy link
Collaborator

ccxvii commented Feb 25, 2025

If you want the coordinates to use with PDFAnnotation or the other public methods of mupdf.js, you need to figure out the position relative to the page image that you display. Transform these coordinates by the display matrix you used to render the page to reverse any scaling you've applied.

If you need to convert to the internal PDF coordinate space, use the PDFPage getTransform matrix.

@ccxvii ccxvii closed this as completed Feb 25, 2025
@benjinus
Copy link
Author

@ccxvii

if the pdf page has no rotation, i can get the right coordinate by apply the matrix from PDFPage.getTransform. but if the page rotation is not 0, the coordinate applied with page matrix is not correct. any ideals why?

@ccxvii
Copy link
Collaborator

ccxvii commented Feb 26, 2025

The transform matrix maps from the PDF page space. Did you invert the matrix to transform the other direction?

@benjinus
Copy link
Author

@ccxvii

thanks, i will try invert the matrix.

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