New to Telerik UI for WinForms? Download free 30-day trial

PdfViewer get the clicked position on the page

Product Version Product Author
2020.2.512.40 RadPdfViewer Dimitar Karamfilov

Description

This article shows how you can get the position when the user clicks on a specific page. The position relates to the upper left corner of the page.

Solution

Use the following code to calculate the position:

public RadForm1()
{
    InitializeComponent();
    radPdfViewer1.MouseDown += RadPdfViewer1_MouseDown;
}

private void RadPdfViewer1_MouseDown(object sender, MouseEventArgs e)
{
    var element = radPdfViewer1.ElementTree.GetElementAtPoint(((MouseEventArgs)e).Location) as RadFixedPageElement;

    if (element != null)
    {

        var mouseLocation = ((MouseEventArgs)e).Location;
        var tt = element.TotalTransform;
        tt.Invert();

        var pointInDoc = tt.TransformPoint(mouseLocation);

        currentPageIndex = radPdfViewer1.Document.Pages.IndexOf(element.Page);
        var zoom = radPdfViewer1.PdfViewerElement.ScaleFactor;

        Console.WriteLine("PageNo: {0} X:{1} Y:{2}", currentPageIndex, pointInDoc.X / zoom, pointInDoc.Y / zoom);
    }
}
In this article