PDFViewWPD annotation onClick action ?

94 views
Skip to first unread message

Barry O'Neill

unread,
Feb 6, 2015, 12:41:45 PM2/6/15
to pdfne...@googlegroups.com
Hi,

I need a custom method to run whenever a user clicks on an annotation (I'm using Highlights). I need to also have a handle on the clicked annotation object as well. I'm not seeing how to do in the API/Examples.

Thanks,

Barry

Barry O'Neill

unread,
Feb 8, 2015, 11:01:02 AM2/8/15
to pdfne...@googlegroups.com
FYI...I'm using .Net/C# and the PDFViewWPF viewer !

The user needs to be able to create highlights (annotations) at will, and get a handle on an existing highlight (annotation) when the user clicks on it.

Thanks...Barry

Ryan

unread,
Feb 12, 2015, 7:59:20 PM2/12/15
to pdfne...@googlegroups.com
Please check out my other reply for more details, but everything you want to do is in the PDFViewWPFTools code. Either modify an existing tool, or add your own new one based on an existing one.

Barry O'Neill

unread,
Feb 13, 2015, 11:48:48 AM2/13/15
to pdfne...@googlegroups.com
This how I ended up doing...

i had for forage ahead with alot of trial and error, due to the slow answer rate in this Group. I needed the method to trigger on a single click, not a double click...



private PDFViewWPF _pdfViewer;
private bool _userClick = false;
private Annot _annotFromClick;
private System.Windows.Point _userClickPoint;
       .
       .
       .
        private void PdfViewer_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            _userClick = false;
        }

        private void PdfViewer_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            _userClick = true;
            _userClickPoint = e.GetPosition(_pdfViewer); //X and Y of mouse position *within viewer*
        }


        private void PdfViewer_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            Page currentPage;

            if (_userClick)
            {
                double x = _userClickPoint.X;
                double y = _userClickPoint.Y;

                _pdfViewer.ConvScreenPtToPagePt(ref x, ref y, _pdfViewer.CurrentPageNumber);
                currentPage = _pdfDocument.GetPage(_pdfViewer.CurrentPageNumber);

                try
                {
                    int annot_num = currentPage.GetNumAnnots();

                    for (int i = 0; i < annot_num; ++i)
                    {
                        Annot parsingAnnot = currentPage.GetAnnot(i);
                        if (parsingAnnot.IsValid() == false || parsingAnnot.GetType() !=
                            Annot.Type.e_Highlight) continue;
                        Rect box = parsingAnnot.GetRect();

                        if (box.Contains(x, y))
                        {
                            //*WE HAVE A MATCHING ANNOTATION*
                            _annotFromClick = new Annot(parsingAnnot);

                           //FROM THIS POINT I CAN RUN MY BUSINESS LOGIC WITH A HANDLE ON THE ANNOTATION THAT WAS CLICKED ON

                        }
                    }

                }
                catch { //no annots on page 
                }

 }


On Friday, 6 February 2015 12:41:45 UTC-5, Barry O'Neill wrote:
Reply all
Reply to author
Forward
0 new messages