detecting select text tool finished

PDF-XChange Editor SDK for Developers

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
EricAriens
User
Posts: 130
Joined: Tue May 03, 2016 1:11 pm

detecting select text tool finished

Post by EricAriens »

Hi,

I want to detect when finished with the Select Text Tool.
I want to do use the data to create a link with InsertNewAnnot
I have checked the evenlist but could not find the appropriate event.

Regards
Eric
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: detecting select text tool finished

Post by Sasha - Tracker Dev Team »

Hello Eric,

The e.docSelection.changed should be used. I believe I posted this sample here not long ago:

Code: Select all

if (e.nEventID == nIDS[(int)IDS.e_docSelection_changed])
{
	PDFXEdit.IPXV_Document Doc = (PDFXEdit.IPXV_Document)e.pFrom;
	uint nLen = e.pEvent.Param2;
	var buffer = new int[nLen];
	IntPtr ptr = new IntPtr(e.pEvent.Param1);
	if ((ptr != null) && (nLen != 0))
	{
		Marshal.Copy(ptr, buffer, 0, (int)nLen);
		for (uint i = 0; i < nLen; i++)
		{
			PDFXEdit.IPXV_DocSelection docSel = Doc.GetSelCluster(buffer[i]);
			PDFXEdit.IPXV_TextSelection pts = docSel as PDFXEdit.IPXV_TextSelection;
		}
	}
}
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
EricAriens
User
Posts: 130
Joined: Tue May 03, 2016 1:11 pm

Re: detecting select text tool finished

Post by EricAriens »

Hi,

Possible. I ask so many questions sometimes I mix things up. Sorry for that.

I copied your code into the FullDemo.
What is is supposed to do.
When I start a text selection the event fires.
docSel and pts are local so they will be destroyed as the event handler closes.
How can I get the selected text info?

Regards
Eric
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: detecting select text tool finished

Post by Sasha - Tracker Dev Team »

Well you can get a string of the text in the selection each time it changes:

Code: Select all

if (pts.IsEmpty == false)
{
	PDFXEdit.IPXV_PageTextSelection pageTextSel = pts.GetSel(pdfCtl.CurrentPage);
	string sText = pageTextSel.GetPlainText();
}
The selection itself can also be done by keyboard shortcuts - this method will also work. You can filter it by monitoring whether the Select Text tool is active if you need to.
Though telling when the selection will end is problematic though possible. When it starts you can remember a text string at the each separate moment of time. Then you can listen to the mouse up event in the pages view handler and then if you have any text in your string you'll do the annotation insertion.
That should work.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
EricAriens
User
Posts: 130
Joined: Tue May 03, 2016 1:11 pm

Re: detecting select text tool finished

Post by EricAriens »

Hi,

I did some testing in the full demo and found something interesting.
When I select a test with the SelectTextTool and opening the context menu I can create a link on the selected text.
This is what I want but then automated.
Selecting the text an then automatically adding a link to the selected text.

Any ideas to make this possible?

When I create a link with the InsertNewAnnot the link will be on the square (I think)

Regards
Eric
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: detecting select text tool finished

Post by Sasha - Tracker Dev Team »

Well you can follow the algorithm that I described before and just execute the addLink command to create the link over the selected text.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
EricAriens
User
Posts: 130
Joined: Tue May 03, 2016 1:11 pm

Re: detecting select text tool finished

Post by EricAriens »

Hi,

By addLink you mean InsertNewAnnot or some other method?
On what should I add the link. On pageTextSel?

Regards
Eric
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: detecting select text tool finished

Post by Sasha - Tracker Dev Team »

1. You started to select the text with the Select Text tool (you put up a bool flag for that if at least one symbol was selected).
2. You monitor the mouse up event for the Pages View. If the bool flag is set then it means that you've used the select text tool. Now you can execute the addLink command via the ExecCmd method. It will automatically add the link to the selected text.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
EricAriens
User
Posts: 130
Joined: Tue May 03, 2016 1:11 pm

Re: detecting select text tool finished

Post by EricAriens »

Hi,

Thanks. I think I can this to work.

Regards
Eric
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: detecting select text tool finished

Post by Sasha - Tracker Dev Team »

:wink:
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
EricAriens
User
Posts: 130
Joined: Tue May 03, 2016 1:11 pm

Re: detecting select text tool finished

Post by EricAriens »

Hi,

When I use the addLink command the user has to do some actions. Can I automate that also?

Regards
Eric
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: detecting select text tool finished

Post by Sasha - Tracker Dev Team »

Hello Eric,

What action exactly do you need to put into the link's actions list?
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
EricAriens
User
Posts: 130
Joined: Tue May 03, 2016 1:11 pm

Re: detecting select text tool finished

Post by EricAriens »

Hi,

I want to add an url to the link(type PXC_TriggerType.Trigger_Up), set the border to underline and set the color

Regards
Eric
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: detecting select text tool finished

Post by Sasha - Tracker Dev Team »

Hello Eric,

Do you need to hardcode the link or just show the "Add URI Action" dialog?

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
EricAriens
User
Posts: 130
Joined: Tue May 03, 2016 1:11 pm

Re: detecting select text tool finished

Post by EricAriens »

Hi,

Hardcode every thing.
The user clicks on a button and the selects a text. After that the rest should go automatically.

Regards
Eric
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: detecting select text tool finished

Post by Sasha - Tracker Dev Team »

Hello Eric,

Sadly, but you will need to place the annotations manually. Below, there is a sample on how to correctly run through the selected text:

Code: Select all

private void getTextSelectionToolStripMenuItem_Click(object sender, EventArgs e)
{
	int nSel = pdfCtl.Inst.Str2ID("selection.text");
	PDFXEdit.IPXV_DocSelection docSel = pdfCtl.Doc.GetSel(nSel);
	PDFXEdit.IPXV_TextSelection ts = docSel as PDFXEdit.IPXV_TextSelection;
	for (uint i = 0; i < ts.Count; i++)
	{
		PDFXEdit.IPXV_PageTextSelection pts = ts[i];
		if (pts.IsEmpty)
			continue;
		PDFXEdit.IPXC_Page page = pdfCtl.Doc.CoreDoc.Pages[pts.PageIndex];
		PDFXEdit.IPXC_PageText pText = page.GetText(null, false);
		for (uint j = 0; j < pts.RangesCount; j++)
		{
			uint rng_fc = 0;
			uint rng_cc = 0;
			pts.GetRange(j, out rng_fc, out rng_cc);
			for (uint k = 0; k < rng_cc; k++)
			{
				uint ci = rng_fc + k;
				if (ci >= pText.CharsCount)
					break;
				//Here the char flags should be used 
				//bool bLineBegin = ((pText.get_CharFlags(ci) & (uint)PDFXEdit.PXC_TextCharFlags.TCF_LineBegin) || (pText.get_CharFlags(ci) & (uint)PDFXEdit.PXC_TextCharFlags.TCF_ParaBegin));
				//Also the pText.get_CharRect method will be used for the rectangle extraction
				//Then you will have the coordinates for the link annotation placement
			}
		}
	}
}
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
CliveO
User
Posts: 5
Joined: Fri Nov 29, 2019 7:24 am

Re: detecting select text tool finished

Post by CliveO »

Sasha - Tracker Dev Team wrote: Thu Jun 30, 2016 11:56 am Hello Eric,

The e.docSelection.changed should be used. I believe I posted this sample here not long ago:

Code: Select all

if (e.nEventID == nIDS[(int)IDS.e_docSelection_changed])
{
	PDFXEdit.IPXV_Document Doc = (PDFXEdit.IPXV_Document)e.pFrom;
	uint nLen = e.pEvent.Param2;
	var buffer = new int[nLen];
	IntPtr ptr = new IntPtr(e.pEvent.Param1);
	if ((ptr != null) && (nLen != 0))
	{
		Marshal.Copy(ptr, buffer, 0, (int)nLen);
		for (uint i = 0; i < nLen; i++)
		{
			PDFXEdit.IPXV_DocSelection docSel = Doc.GetSelCluster(buffer[i]);
			PDFXEdit.IPXV_TextSelection pts = docSel as PDFXEdit.IPXV_TextSelection;
		}
	}
}
Cheers,
Alex
Hi All,

I am new to this forum, and using an evaluation copy of the PDFXEdit control.
I know this is an old post, but it contains exactly what I need.
I have FullDemo, but am at a loss as to where the above code should be added to catch document selection changed event.
I notice the pdfCtl_OnEvent does not register an event when text is selected.

Any help would be much appreciated.

Regards,
Clive
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: detecting select text tool finished

Post by zarkogajic »

Hi Clive,

You need to EnableEventListening as in here: viewtopic.php?p=94313#p94313

List of events you can listen to: https://sdkhelp.pdf-xchange.com/vi ... PXV_Events

-žarko
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: detecting select text tool finished

Post by Sasha - Tracker Dev Team »

Thanks for the explanation žarko :)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
CliveO
User
Posts: 5
Joined: Fri Nov 29, 2019 7:24 am

Re: detecting select text tool finished

Post by CliveO »

Sasha - Tracker Dev Team wrote: Thu Jun 30, 2016 11:56 am Hello Eric,

The e.docSelection.changed should be used. I believe I posted this sample here not long ago:

Code: Select all

if (e.nEventID == nIDS[(int)IDS.e_docSelection_changed])
{
	PDFXEdit.IPXV_Document Doc = (PDFXEdit.IPXV_Document)e.pFrom;
	uint nLen = e.pEvent.Param2;
	var buffer = new int[nLen];
	IntPtr ptr = new IntPtr(e.pEvent.Param1);
	if ((ptr != null) && (nLen != 0))
	{
		Marshal.Copy(ptr, buffer, 0, (int)nLen);
		for (uint i = 0; i < nLen; i++)
		{
			PDFXEdit.IPXV_DocSelection docSel = Doc.GetSelCluster(buffer[i]);
			PDFXEdit.IPXV_TextSelection pts = docSel as PDFXEdit.IPXV_TextSelection;
		}
	}
}
Cheers,
Alex
That works so well, thank you!
Attachments
PDF1.jpg
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: detecting select text tool finished

Post by Sasha - Tracker Dev Team »

:)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply