Get Page Coordinates of Mouse Click

4 posts, 0 answers
  1. Patrick
    Patrick avatar
    2 posts
    Member since:
    Feb 2015

    Posted 10 Jun 2016 Link to this post

    I am sure this is an instance when my ignorance will show through, but I am on a deadline and at my wits end. I am trying to have a text appear in an existing PDF based on a position the end-user clicks on the PDF. I when I provide coordinates I can get the text to appear, but I do not always know the coordinates. For the life of me I cannot figure out how to get the PDF Document Coordinates based on the mouse down event. The idea is I am receiving different documents, but they all contain a blank spot to fill in a Name. That position could be different depending on who is sending the document.

    I am using WinForms and vb.net. I have found plenty of dead-ends on this process including a suggestion of making a custom provider, but that does not seem to work in WinForms.

     

    Any suggestions on how to calculate the page coordinates or another alternative that could display a ruler or the like to allow the user to enter measurements that I can then convert.

    Thank you in advance for any help.

  2. Dimitar
    Admin
    Dimitar avatar
    1544 posts

    Posted 13 Jun 2016 Link to this post

    Hi Patrick,

    Thank you for writing.

    The following code snippet shows how you can get the position:
    Private Sub RadPdfViewer1_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim element = TryCast(radPdfViewer1.ElementTree.GetElementAtPoint(CType(e, MouseEventArgs).Location), RadFixedPageElement)
        If element IsNot Nothing Then
            Dim mouseLocation = CType(e, MouseEventArgs).Location
            Dim tt = element.TotalTransform
            tt.Invert()
            Dim pointInDoc = tt.TransformPoint(mouseLocation)
     
            Console.WriteLine(pointInDoc)
        End If
     
    End Sub

    Could you test this with your documents and let me know how it works on your side?

    I am looking forward to your reply.

    Regards,
    Dimitar
    Telerik
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
  3. Patrick
    Patrick avatar
    2 posts
    Member since:
    Feb 2015

    Posted 11 Dec 2016 in reply to Dimitar Link to this post

    Dimitar,

    I apologize about the delayed response and also that the delay has also clouded my memory. Anyway, the above code did in fact lead me to a solution. From my notes it looks as though I had to do a bit of math to get the exact positioning, but that may have been necessary for our final output.

    Thank you

  4. Dimitar
    Admin
    Dimitar avatar
    1544 posts

    Posted 12 Dec 2016 Link to this post

    Hello Patrick,

    I am glad that you have found a solution for this. Please do not hesitate to contact us with any additional questions or concerns. 
     
    Regards,
    Dimitar
    Telerik by Progress
    Telerik UI for WinForms is ready for Visual Studio 2017 RC! Learn more.
Back to Top