Get coordinates from mouse up event in PDFViewWPF ?

71 views
Skip to first unread message

Barry O'Neill

unread,
Feb 7, 2015, 12:29:11 PM2/7/15
to pdfne...@googlegroups.com
Hi,

I need to capture the mouse coordinates of a mouse click in my open doc/page within the PDFViewWPF.

I need to use the coordinates in an effort to find a matching annotation from a list of annotations for the entire document (book). At the end of the day I need to capture the annotation the user clicked on, but I need to be in ToolType.e_text_highlight mode all the time so the user can create highlights at will, but so I can also capture a click on an existing highlight to run a custom method against the clicked annotation, to satisfy my business requirements.


Something like this:


private PDFViewWPF _pdfViewer;
.
.
.
//open doc in viewer etc.
//in highlight mode all the time, user adds a bunch of highlights
//need to capture when an existing highlight is clicked
.
.
.
 _pdfViewer.MouseUp += _pdfViewer_MouseUp;
.
.
.
private void _pdfViewer_MouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{

//GET [CLICKED COORDINATES WITHIN PAGE], and then...

   for (var i = 0; i < _allBookAnnotations.Count(); i++) {

        Annot anAnnot = _allBookAnnotations[i];

        if (anAnnot.GetPage().GetIndex() - 1 ==  [CLICKED COORDINATES WITHIN PAGE].pageIndex) {

            var rect = {
                x1: annot.GetLeft(),
                y1: annot.GetTop(),
                x2: annot.GetRight(),
                y2: annot.GetBottom()
            };
            if (pageCoordinate.x >= rect.x1 && pageCoordinate.x <= rect.x2 && pageCoordinate.y >= rect.y1 && pageCoordinate.y <= rect.y2) {
                WE HAVE A MATCHING ANNOTATION FOR CLICK;
            }
        }

   }



}


Thanks,....Barry

Ryan

unread,
Feb 12, 2015, 7:58:10 PM2/12/15
to pdfne...@googlegroups.com
Hi Barry. All the user interaction code for PDFViewWPF is in the PDFViewWPFTools project. You can either modify an existing tool, or create a new one based on an existing one.

Also PDFViewWPF has a method ConvScreenPtToPagePt, which you would use to convert the mouse click x,y to the x,y you can use to compare against annots.

Better yet, there is a method PDFViewWPF.GetAnnotationAt that will do all this for you, just pass in the mouse x,y.

Otherwise you look to be on the right track

Barry O'Neill

unread,
Feb 17, 2015, 2:25:02 PM2/17/15
to pdfne...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages