We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Mouse coordinates to document coordinates

Hi,

I experimented with the PDFViewer control. I am trying to figure out how to get a coordinate in the document coordinate system from a given mouse coordinate.
My sample PDF's single page has a height of 792 and width of 612. I am not sure, which unit those coordinates are in. I can for sure say, that those don't correlate to pixels as on my screen.
So if I click on the pdf document, the current mouse position shall be converted to a document coordinate. This should be possible regardless of the zoom factor applied to the viewer control and regardless of any "free space" around the actual document in the viewer.

Thanks for your support.
Florian


3 Replies

SS Sathish Sivakumar Syncfusion Team June 23, 2016 01:26 PM UTC

Hi Florian, 
 
We have created the Direct-trac support incident to this forum for further follow up, please login to your direct trac account to know more about details about incident.  
 
  
Regards, 
Sathish 



AM Amit October 23, 2017 01:20 PM UTC

Hi Team,

Is this feature can be achieved, can we get the mouse coordinates on pdf?



SS Sathish Sivakumar Syncfusion Team October 24, 2017 12:45 PM UTC

Hi Amit, 
  
Thank you for your patience.  
  
We have already provided the support for “Finding coordinate of the mouse click over the page in the PDF document” using PdfViewer control in WPF from the Essential Studio Vol 2 2016. 
  
Please find the code snippet to find the coordinate of the mouse click over the page in the PDF document:  
  
Code Snippet:  
  
//Creating PageClicked event to find the coordinate of the mouse click over the page in the PDF document  
pdfViewer.PageClicked += pdfViewer_PageClicked;  
  
//PageClicked event  
void pdfViewer_PageClicked(object sender, Syncfusion.Windows.PdfViewer.PageClickedEventArgs args)  
{  
  
  
}  
  
Note: PageClickedEventArgs contains following Properties  
  
1.       PageIndex : Current index of the page in the PDF document being clicked using Mouse  
2.       Position : Returns the coordinates (in Pixels) of the mouse click over the page in the PDF document  
  
We can convert the pixel coordinate to the document coordinate (i.e. Point) using PdfUnitConvertor class.  
  
Note:  
  
  • The coordinates returned by the PageClicked event does not depend on the zoom factor applied to the PdfViewerControl. 
  • The PageClicked event cannot be triggered if we clicked the mouse on the free space around the page in the PdfViewerControl. 
  
We have also created a simple sample to find the coordinates of the mouse click over the page in the PDF document:  
  
  
Please let us know if you need further assistance.  
  
Regards,  
Sathish  


Loader.
Up arrow icon