select some rectangle area and just return coordinates

So there is no need to actually draw anything, just visually pick up some rectangle area i.e. its coordinates within page.
This rectangle area will be used later for signature position.
I would appreciate any code example, if possible without integrating some of wpf components
Thanks
Darko

5 Replies 1 reply marked as answer

DD Divya Dhayalan Syncfusion Team December 21, 2020 05:13 PM UTC

Hi Darko, 
 
Thanks for contacting Syncfusion support. 
 
We can obtain the mouse coordinates within a page using the PageClicked and PageMouseMove Events in PdfViewerControl. Please refer the below code for the same. 
 
PdfUnitConvertor convertor = new PdfUnitConvertor(); 
        public PdfViewer() 
        { 
            InitializeComponent(); 
            pdfViewerControl1.PageMouseMove += Pdfviewer_Pagemousemove; 
            pdfViewerControl1.PageClicked += PdfViewer_PageClicked; 
            pdfViewerControl1.Load(@"../../Data/Barcode.pdf"); 
        } 
         
        void Pdfviewer_Pagemousemove(object sender, PageMouseMoveEventArgs args) 
        { 
            if (pdfViewerControl1.InvokeRequired) 
            { 
                moveIndexBox.Invoke(new Action(() => moveIndexBox.Text = args.PageIndex.ToString())); 
                moveXPositionBox.Invoke(new Action(() => moveXPositionBox.Text = convertor.ConvertFromPixels((float)args.Position.X, PdfGraphicsUnit.Point).ToString())); 
                moveYPositionBox.Invoke(new Action(() => moveYPositionBox.Text = convertor.ConvertFromPixels((float)args.Position.Y, PdfGraphicsUnit.Point).ToString())); 
            } 
            else 
            { 
                moveIndexBox.Text = args.PageIndex.ToString(); 
                System.Drawing.PointF mousePosition = args.Position; 
                moveXPositionBox.Text = convertor.ConvertFromPixels((float)args.Position.X, PdfGraphicsUnit.Point).ToString(); 
                moveYPositionBox.Text = convertor.ConvertFromPixels((float)args.Position.Y, PdfGraphicsUnit.Point).ToString(); 
            } 
 
        } 
 
        void PdfViewer_PageClicked(object sender, PageClickedEventArgs args) 
        { 
            clickIndexBox.Text = args.PageIndex.ToString(); 
            clickXPositionBox.Text = convertor.ConvertFromPixels((float)args.Position.X, PdfGraphicsUnit.Point).ToString(); 
            clickYPositionBox.Text = convertor.ConvertFromPixels((float)args.Position.Y, PdfGraphicsUnit.Point).ToString();             
        } 
 
Please find the below UG link to know more about the PageClicked and PageMouseMove Events: 
 
Please let us know if the above details are helpful and if you need any further assistance on this. 
 
Regards, 
Divya 



DA Darko December 22, 2020 06:13 PM UTC

Appreciate for code but I am struggling with this and didn't succeeded to make a proper exe, sorry.
Any chance to find somewhere complete c# example?

Or if it would be easier with WPF PdfViewer that would be also good as I need "run program -> open pdf -> select rectangle area -> write coordinates &dimensions -> exit program". As I said before I need this rectangle area for digital signature position and dimensions.
Many thanks
Darko



DD Divya Dhayalan Syncfusion Team December 23, 2020 11:49 AM UTC

Hi Darko, 
 
Thanks for providing some more information. 
 
We have analyzed your requirement and created a Windows Forms application which hosts a WPF PdfViewerControl (Since we do not have rectangle drawing support in WinForms). In this you can draw rectangle annotation over the PDF and get the coordinates (position, page number, and size) from the event arguments of the ShapeAnnotationChanged event. We have created a video and a sample for your requirement, and it can be downloaded from the below link. 
 
 
Note: You can handle exiting the program after getting the coordinates from the EventArgs. 
 
Please find the below UG link to know more about ShapeAnnotationChanged Event and setting Rectangle AnnotationMode 
 
 
Please let us know if the above details help. 
 
Regards, 
Divya 


Marked as answer

DA Darko December 23, 2020 04:54 PM UTC

What can I say except "Perfect !!!"
Really good,  now I can write down those values as soon as rectangle is closed and force exit from pdf viewer after this.
Thanks a lot for your help and for your time

Kind regards
Darko


DD Divya Dhayalan Syncfusion Team December 24, 2020 07:39 AM UTC

Hi Darko, 
 
Most Welcome. Please let us know if you need any further assistance on this. 
 
Regards, 
Divya

Loader.
Up arrow icon