Selected Text offset

PDF-XChange Viewer SDK for Developer's
(ActiveX and Simple DLL Versions)

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

jykim
User
Posts: 37
Joined: Fri Oct 02, 2009 12:30 am

Selected Text offset

Post by jykim »

Hi,

Is it possible to get the offset of currently selected text?
I see that there's way to get the selected text using -

Code: Select all

DoVerb("Documents[0].Pages[0].Text", "GetSelected", DataIn(1), DataOut, 0);
but, it only gives me the text.
Please help.
User avatar
Vasyl - PDF-XChange
Site Admin
Posts: 2448
Joined: Thu Jun 30, 2005 4:11 pm

Re: Selected Text offset

Post by Vasyl - PDF-XChange »

Hi,
No way for this in current realization.
But new method "GetSelectedRanges" will be added into the next release (2.42.5 build, coming soon) such as:

Code: Select all

DoVerb("Documents[#<docID>].Pages[0].Text", "GetSelectedRanges", dataIn, dataOut, 0);
// or
DoDocumentVerb(docID, "Pages[0].Text", "GetSelectedRanges", dataIn, dataOut, 0);
// we can obtain one(usually), two(and more) segment(s):
int firstChar1 = dataOut[0];
int countChars1 = dataOut[1];
int firstChar2 = dataOut[2];
int countChars2 = dataOut[3];
...
Best
Regards
PDF-XChange Co. LTD (Project Developer)

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
User avatar
Vasyl - PDF-XChange
Site Admin
Posts: 2448
Joined: Thu Jun 30, 2005 4:11 pm

Re: Selected Text offset

Post by Vasyl - PDF-XChange »

Hi,
Additionally, new method will be added for obtain pages with selection, such as:

Code: Select all

DoDocumentVerb(docID, "Pages", "GetSelectedRanges", dataIn, dataOut, 0);
// we can obtain one(usually), two(and more) page-ranges(s):
int firstPageWithSel1 = dataOut[0];
int countPagesWithSel1 = dataOut[1];
int firstPageWithSel2 = dataOut[2];
int countPagesWithSel2 = dataOut[3];
...
Best
Regards
PDF-XChange Co. LTD (Project Developer)

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
jykim
User
Posts: 37
Joined: Fri Oct 02, 2009 12:30 am

Re: Selected Text offset

Post by jykim »

Vasyl,

Thanks very much for your reply. I have some follow-up questions -

1. In the sample code for the new method "GetSelectedRanges", what's the meaning of "countChars" (int countChars1 = dataOut[1];)? Is it number of characters in the selection? or, is it number of characters within the page upto the selection?
2. How would the new method "GetSelectedRanges" be useful for my requirement? (to get the offset - character count upto the selection within the page)
3. With the viewer product, you can select some text and you can highlight it using a toolbar button. So, I was guessing, there should be a way to detect current text selection (as an object or some sort) in your internal viewer implementation. If that's true, would it be possible to make that API available in SDK?

Thanks for your help.
jykim
User
Posts: 37
Joined: Fri Oct 02, 2009 12:30 am

Re: Selected Text offset

Post by jykim »

I had more questions for Vasyl,

1. In your sample code for the new method "GetSelectedRanges", what's the meaning of "countChars" (int countChars1 = dataOut[1];)? Is it number of characters in the selection? or, is it number of characters within the page upto the selection?
2. How would the new method "GetSelectedRanges" be useful for my requirement? (to get the offset - character count upto the selection within the page)
3. With the viewer product, you can select some text and you can highlight it using a toolbar button. So, I was guessing, there should be a way to detect current text selection (as an object or some sort) in your internal viewer implementation. If that's true, would it be possible to make that API available in SDK?

I was thinking of something like these -

Code: Select all

DoVerb("Documents[0].Pages[0].Text.Selection.Offset", "get", DataIn, DataOut, 0);
or

Code: Select all

DoVerb("Documents[0].Pages[0].SelectedText.Offset", "get", DataIn, DataOut, 0);
User avatar
Vasyl - PDF-XChange
Site Admin
Posts: 2448
Joined: Thu Jun 30, 2005 4:11 pm

Re: Selected Text offset

Post by Vasyl - PDF-XChange »

Hi,
1. In the sample code for the new method "GetSelectedRanges", what's the meaning of "countChars" (int countChars1 = dataOut[1];)? Is it number of characters in the selection? or, is it number of characters within the page upto the selection?
2. How would the new method "GetSelectedRanges" be useful for my requirement? (to get the offset - character count upto the selection within the page)
The text-selection can contains some(typically one) ranges, for example, you can select some text by mouse with pressed 'Alt' key (alternate text-selection mode).
Each text-selection range contains:
1. index of start-character(begin of range)
2. count of characters in this range.
the index of last character in each range can be calculated as: <index of start-character> + <count of characters> - 1.
So, to get selection offset on the page you can use fist number from obtained array of numbers from the dataOut.
For example some ranges: 1-1, 5-10, 100-1.

Code: Select all

3. With the viewer product, you can select some text and you can highlight it using a toolbar button. So, I was guessing, there should be a way to detect current text selection (as an object or some sort) in your internal viewer implementation. If that's true, would it be possible to make that API available in SDK?
1. In the new build you will be able to receive special events about selection changes (look to Reference->Named Items->Objects->Notifications->Selection in the new SDK Help).
2. For detect pages which contains selected text you will be able to use:

Code: Select all

DoDocumentVerb(docID, "Pages", "GetSelectedRanges", dataIn, dataOut, 0);
3. For obtain text-selection ranges for each page, call:

Code: Select all

DoDocumentVerb(docID, "Pages[<Index>].Text", "GetSelectedRanges", dataIn, dataOut, 0);
4. You may obtain text from each text-selection range by:

Code: Select all

DoDocumentVerb(docID, "Pages[<Index>].Text", "Get", dataIn(FirstCharIndex, CountOfChars), dataOut, 0);
5. You may highlight/underline/strikeout each text-selection range by:

Code: Select all

DoDocumentVerb(docID, "Pages[<Index>].Text", "Highlight", dataIn(FirstCharIndex, CountOfChars), dataOut, 0);
DoDocumentVerb(docID, "Pages[<Index>].Text", "Underline", dataIn(FirstCharIndex, CountOfChars), dataOut, 0);
DoDocumentVerb(docID, "Pages[<Index>].Text", "StrikeOut", dataIn(FirstCharIndex, CountOfChars), dataOut, 0);
And about:

Code: Select all

DoVerb("Documents[0].Pages[0].Text.Selection.Offset", "get", DataIn, DataOut, 0);
DoVerb("Documents[0].Pages[0].SelectedText.Offset", "get", DataIn, DataOut, 0);
-in the future we planning to realize special object named as 'Selection' with more features like as:

Code: Select all

DoDocumentVerb(docID, "Selection.Pages", "get", dataIn, dataOut, 0);
DoDocumentVerb(docID, "Selection.Annots", "get", dataIn, dataOut, 0);
DoDocumentVerb(docID, "Selection.Bookmarks", "get", dataIn, dataOut, 0);
DoDocumentVerb(docID, "Selection", "Delete", dataIn, dataOut, 0);
DoDocumentVerb(docID, "Selection", "Copy", dataIn, dataOut, 0);
DoDocumentVerb(docID, "Selection", "Clear", dataIn, dataOut, 0);
...
Thanks.
PDF-XChange Co. LTD (Project Developer)

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
jykim
User
Posts: 37
Joined: Fri Oct 02, 2009 12:30 am

Re: Selected Text offset

Post by jykim »

Thanks Vasyl. You're the best! :)
I'm looking forward to trying out the new version with new API.
Cheers!
User avatar
John - Tracker Supp
Site Admin
Posts: 5223
Joined: Tue Jun 29, 2004 10:34 am

Re: Selected Text offset

Post by John - Tracker Supp »

;)
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.

Best regards
Tracker Support
http://www.tracker-software.com
jykim
User
Posts: 37
Joined: Fri Oct 02, 2009 12:30 am

Re: Selected Text offset

Post by jykim »

Hi Vasyl,

I've downloaded the new version (v.2.042.6), but I can't find "GetSelectedRanges" in the manual document.
Is it included in the new version, and just missing from the manual document?
Or, is it not included in the new version?
jykim
User
Posts: 37
Joined: Fri Oct 02, 2009 12:30 am

Re: Selected Text offset

Post by jykim »

Hi Vasyl,

Regarding the sample code you've provided above -

Code: Select all

DoVerb("Documents[#<docID>].Pages[0].Text", "GetSelectedRanges", dataIn, dataOut, 0);
// or
DoDocumentVerb(docID, "Pages[0].Text", "GetSelectedRanges", dataIn, dataOut, 0);
// we can obtain one(usually), two(and more) segment(s):
int firstChar1 = dataOut[0];
int countChars1 = dataOut[1];
int firstChar2 = dataOut[2];
int countChars2 = dataOut[3];
...
I guess that "dataOut" is a Variant that contains an array. If that's the case, I won't be able to implement such a thing in my Java/SWT ActiveX environment. Please see this thread - http://www.docu-track.com/forum3/viewto ... =36&t=7079.
So, I'm wondering if you could add new interfaces to support that. I'm thinking of something like this -

Code: Select all

Variant dataOut = new Variant(OS.GlobalAlloc(OS.GMEM_FIXED | OS.GMEM_ZEROINIT, Variant.sizeof), (short)(OLE.VT_BYREF | OLE.VT_DISPATCH));
DoDocumentVerb(docID, "Pages", "GetSelectedRanges", dataIn, dataOut, 0);

OleAutomation outputs = dataOut.getAutomation();

Variant firstPageWithSel1  = outputs.invoke(getDispId(outputs,"Get"), new Variant[]{new Variant(0)});
Variant countPagesWithSel1 = outputs.invoke(getDispId(outputs,"Get"), new Variant[]{new Variant(1)});
Variant firstPageWithSel1  = outputs.invoke(getDispId(outputs,"Get"), new Variant[]{new Variant(2)});
Variant countPagesWithSel2 = outputs.invoke(getDispId(outputs,"Get"), new Variant[]{new Variant(3)});

Corwin - Tracker Sup
User
Posts: 664
Joined: Tue Nov 14, 2006 12:23 pm

Re: Selected Text offset

Post by Corwin - Tracker Sup »

In new build we will try to add possibility to get output values thru IPDFXCargs (our own implementation of SafeArray).

Thanks for patience.
jykim
User
Posts: 37
Joined: Fri Oct 02, 2009 12:30 am

Re: Selected Text offset

Post by jykim »

Thanks Corwin. I'm looking forward to it.