This is a migrated thread and some comments may be shown as answers.

Get Page Coordinates of Mouse Click

10 Answers 612 Views
PdfViewer and PdfViewerNavigator
This is a migrated thread and some comments may be shown as answers.
Patrick
Top achievements
Rank 1
Patrick asked on 10 Jun 2016, 06:00 PM

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.

10 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 13 Jun 2016, 07:55 AM
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.Scale(radPdfViewer.ScaleFactor, radPdfViewer.ScaleFactor)
        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.
0
Patrick
Top achievements
Rank 1
answered on 12 Dec 2016, 03:45 AM

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

0
Dimitar
Telerik team
answered on 12 Dec 2016, 11:23 AM
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.
0
Vinod
Top achievements
Rank 1
answered on 16 Feb 2018, 05:10 AM

Hi Patrick,

I am in need of the same task which you have posted.

I should be able to place a text callout on PDF wherever the user clicks on the PDF.

Could you please help me in this.

 

Thanking you in advance,

Vinod Bhaskar Paul.

0
Dimitar
Telerik team
answered on 16 Feb 2018, 12:09 PM
Hi Vinod,

This code still works and will give you the location on the page. However, RadPdfViewer does not support any editing. 

Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Mikko
Top achievements
Rank 1
Veteran
answered on 29 Nov 2020, 06:06 PM

Hello,

I would like use PDF viewer to mark locations to a blueprint.

Users could click on the blueprint (house drawing) and our solution would save the location and also show marking on the location (image over the PDF viewer).

When blueprint is opened we should be able to show markings over the blueprint. Is there a way to find and mark these locations?

User might zoom or scroll the PDF file and we need to check if there are any markings on the area that is currently visible. Also, I think that the cordinates on Windows software and different than in PDF viewer?

Thanks for any help! Please let me know if you need more information.

Best regards, Mikko

 

0
Dimitar
Telerik team
answered on 01 Dec 2020, 12:31 PM

Hi Mikko,

I believe that the best approach is to add the images to the PDF file with the PdfProcessing library. This way they will be stored and you would not need to do anything the next time the file is opened. You would not need to handle the zoom/scrolling as well. I have attached a small sample project that shows this. 

I hope this information is useful. Let me know if you need further assistance.

Regards,
Dimitar
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Mikko
Top achievements
Rank 1
Veteran
answered on 01 Dec 2020, 12:40 PM

Hi Dimitar,
That is a good idea.

Our final goal is a little more challenging. We would like to have a option where users can also remove markings and also to have a popup on mouse click, to show more information regarding the incident/marking. Can we archive this with Annotations or similar?

Thanks for you quick reply and excellent support!

Best regards, Mikko

0
Dimitar
Telerik team
answered on 02 Dec 2020, 04:02 PM

Hello Mikko, 

You can use the fields to add specific locations. For example, you can use the PushButtonField and set its contents (the image). Each field has a widget annotation that has a specific rectangle. This allows you to determine when this rectangle is hovered or clicked and then show tooltip or remove the field. I have updated the project that shows a sample implementation. 

Let me know if you need further assistance.

Regards,
Dimitar
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Mikko
Top achievements
Rank 1
Veteran
answered on 06 Dec 2020, 01:19 PM

Hi Dimitar,
This is exactly what we are looking for. Sample code works fine with a sample PDF, but not with our own.
I have opened a support ticket, as I cannot share the PDF file on public.
Best regards, Mikko

Tags
PdfViewer and PdfViewerNavigator
Asked by
Patrick
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Patrick
Top achievements
Rank 1
Vinod
Top achievements
Rank 1
Mikko
Top achievements
Rank 1
Veteran
Share this question
or