Inserting an image on a PDF at the mouse position

Product: PDFNet SDK for C#

Product Version: 9.3.0

Please give a brief summary of your issue:
Inserting an image on a PDF at the mouse position

Please describe your issue and provide steps to reproduce it:
I want to insert an image on a PDF document by choosing the position with the mouse. I have tried a lot to find the right coordinates but unfortunately no success. Please find below my current code which still inserts the image at a wrong position. What am I doing wrong? Thanks for help! N

/* position of top-left corner of Form1 (screen coords) */
_currentFormPosition = this.Location;

/* offset from viewer to Form1 (screen coords) */
_currentViewerOffset = _pdfView.Location;

/* position of the viewer (screen coords) */
_currentViewerPosition = new System.Drawing.Point(
     _currentFormPosition.X + _currentViewerOffset.X,
     _currentFormPosition.Y + _currentViewerOffset.Y
                );

/* mouse position on the screen (screen coords) */
 _currentMousePosition = new System.Drawing.Point(
    MousePosition.X, 
    MousePosition.Y);

/* position of the mouse on the viewers canvas  */
_currentScreenPosition = new System.Drawing.Point(
    _currentMousePosition.X - _currentViewerPosition.X,
    _currentMousePosition.Y - _currentViewerPosition.Y
                );

/* image insertion point */
int index = _pdfView.GetCurrentPage();
double x = (double)_currentScreenPosition.X;
double y = (double)_currentScreenPosition.Y;
_pdfView.ConvScreenPtToPagePt(ref x, ref y, index);
_currentInsertionPosition = new PointD(x, y); // still wrong

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Guides:APIs:Forums:

_pdfView what class is this? PDFViewCtrl or PDFViewWPF?

Hi Ryan, it is PDFViewCtrl (WinForms) at the moment, but it would be an alternative to go to WPF if that makes things work better.

Regards
Niels

Yes, the PDFViewWPF class is the newer viewer. In particular, all of the UI/UX code is included with the SDK so you can access it all, and even make any changes if you need.

Please see the PDFViewWPFTools and one of the Tools, such as StickyNodeCreate.cs to see how to map mouse point to PDF point.

Don’t forget to doc locking when reading/editing PDF files while also viewing.

Hi Ryan, thank you for the valuable tips. I successfully finished work on my prototype.
Regards
Niels