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);
Please help.
Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange
Code: Select all
DoVerb("Documents[0].Pages[0].Text", "GetSelected", DataIn(1), DataOut, 0);
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];
...
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];
...
Code: Select all
DoVerb("Documents[0].Pages[0].Text.Selection.Offset", "get", DataIn, DataOut, 0);
Code: Select all
DoVerb("Documents[0].Pages[0].SelectedText.Offset", "get", DataIn, DataOut, 0);
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).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)
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?
Code: Select all
DoDocumentVerb(docID, "Pages", "GetSelectedRanges", dataIn, dataOut, 0);
Code: Select all
DoDocumentVerb(docID, "Pages[<Index>].Text", "GetSelectedRanges", dataIn, dataOut, 0);
Code: Select all
DoDocumentVerb(docID, "Pages[<Index>].Text", "Get", dataIn(FirstCharIndex, CountOfChars), dataOut, 0);
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);
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);
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);
...
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];
...
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)});