Drag selected text (WPF)

Hey all.

I'm currently working on implementing drag/copy from a PDF View to a drop target (most likely a tree view of some sort), but I can't figure out of the control actually supports it, or, if not, sample code that shows how to implement it.
The sort of behavior I'm interested in is much like that of most web browsers - highlight some text, then drag it elsewhere (ideally with an adorner layer).
Currently, highlighting text, then attempting to drag, will simply create a new highlight operation.


Hi Michael,

Are you using PDFViewWPF or PDFViewCtrl for your project?
We recommend using PDFViewWPF, as it provides a lot more customization and flexibility when implementing.

With the PDFViewWPF, the text selection is done by the PDFViewWPFTools, which is a sample packaged with the SDK. The PDFViewWPFTools take care of most of the interactive features, such as creating/deleting annotations, filling in forms, and selecting text. This is where you can edit the code to implement drag and drop.

You can implement it by editing the MouseLeftButtonDownHandler/ProcessInputDown or MouseMovedHandler/ProcessInputMove in TextSelectStructural.cs.
I have attached a very basic implementation.

The basic idea is to see if the mouse is currently on top of a quad from selection, which would look something like this:

int downPage = mPDFView.GetPageNumberFromScreenPt(mDownPoint.X, mDownPoint.Y);
if (mSelectionCanvases.ContainsKey(downPage))
double pageX = mDownPoint.X;
double pageY = mDownPoint.Y;
mPDFView.ConvScreenPtToPagePt(ref pageX, ref pageY, downPage);
pageY = mSelectionCanvases[downPage].PageHeight - pageY;
foreach (PDFRect rect in mSelectionCanvases[downPage].Quads)
if (rect.Contains(pageX, pageY))
mDraggingText = true;
mDraggedSelection = mSelectionCanvases[downPage];

I hope this gets you started in the right direction.

Best Regards,
Tomas Hofmann

TextSelectStructural.cs (20.9 KB)