Copy link to clipboard
Copied
In any given textframe it is possible to grab a set of words in that textFrame. Unfortunately, for Word objects I'm unable to find any clear positional data the same way I can find it for pageItems. The main thing I need is pixel coordinates per word.
The build in HTML to FXL conversion script has these pixel coordinates embedded on the <span> element for each word in the HTML. So either these values are exposed to the indesign API and I'm missing it, these values are calculated somehow, or they are values available to indesign internally but not exposed to the API.
Please let me know your thoughts.
Thanks
You can use the baseline+ascent or descent to get a word’s Y1 and Y2 coordinate, and the horizontal offset and end horizontal offset to get the X1 & X2 coordinates. So this would get the bounds of the selection if it is a word or single line.
var sel = app.selection[0];
$.writeln("Selected Text Bounds: " + getTextBounds(sel));
function getTextBounds(t){
var y1, x1, y2, x2
y1 = t.baseline - sel.ascent;
x1 = t.horizontalOffset
y2 = t.baseline + sel.descent;
x2 = t.endHo
...
Copy link to clipboard
Copied
You can use the baseline+ascent or descent to get a word’s Y1 and Y2 coordinate, and the horizontal offset and end horizontal offset to get the X1 & X2 coordinates. So this would get the bounds of the selection if it is a word or single line.
var sel = app.selection[0];
$.writeln("Selected Text Bounds: " + getTextBounds(sel));
function getTextBounds(t){
var y1, x1, y2, x2
y1 = t.baseline - sel.ascent;
x1 = t.horizontalOffset
y2 = t.baseline + sel.descent;
x2 = t.endHorizontalOffset
return [y1,x1,y2,x2]
}
For multiple lines you could test for the longest line and get the Y2 from the end of that line, and the X2 from the lastline baseline + descent
Copy link to clipboard
Copied
Hi Peter,
what's your exact version of InDesign?
Could you detect the word in the exported HTML file with the desired coordinates?
Then I would read out the data from the HTML file.
Regards,
Uwe Laubender
( ACP )