Get selected text

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.
khho
User
Posts: 34
Joined: Fri Mar 11, 2022 11:02 am

Get selected text

Post by khho »

Hi Support,
what is the easiest way to get the selected text in a document.

I'm sure it is posted somwhere here but I can't find it.
I don't need e_docSelection_changed...
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17960
Joined: Mon Jan 12, 2009 8:07 am
Location: London

Re: Get selected text

Post by Tracker Supp-Stefan »

Hello khho,

You will probably need the methods of this interface:
https://sdkhelp.pdf-xchange.com/vi ... tSelection

Kind regards,
Stefan
khho
User
Posts: 34
Joined: Fri Mar 11, 2022 11:02 am

Re: Get selected text

Post by khho »

I do it like this:

Code: Select all

PDFXEdit.IPXV_DocSelection docSel = doc.ActiveSel;
if (docSel is PDFXEdit.IPXV_TextSelection)
{
	PDFXEdit.IPXV_PageTextSelection pageSel = ((PDFXEdit.IPXV_TextSelection)docSel).GetSel(0,true);
	result = pageSel.GetPlainText();
}
What is the best way to determine nPageIndex for GetSel?
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2353
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: Get selected text

Post by Vasyl-Tracker Dev Team »

Hope this will help:

Code: Select all

int selID = pxvInst.Str2ID("selection.text");
PDFXEdit.IPXV_DocSelection docSel = doc.GetSel(selID);
if (docSel != null)
{
      PDFXEdit.IPXV_TextSelection textSel = (PDFXEdit.IPXV_TextSelection)docSel;    

      uint countOfPagesWithSelText = textSel.Count; 
      for (unit i = 0; i < countOfPagesWithSelText; i++) 
      {
             PDFXEdit.IPXV_PageTextSelection pageTextSel = textSel[i];     
             unit pageIndex = pageTextSel.PageIndex;
             ...
             ...
      } 
}
Cheers.
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
khho
User
Posts: 34
Joined: Fri Mar 11, 2022 11:02 am

Re: Get selected text

Post by khho »

Yes, that helped (again)!
With this example I don't need the PageIndex anymore.

Thanks!
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17960
Joined: Mon Jan 12, 2009 8:07 am
Location: London

Get selected text

Post by Tracker Supp-Stefan »

:)