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
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
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
I am glad that you have found a solution for this. Please do not hesitate to contact us with any additional questions or concerns.
Dimitar
Telerik by Progress
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.
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
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
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/.
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
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/.
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