• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Is it possible to access pixel coordinates of individual words within a textframe

New Here ,
May 27, 2020 May 27, 2020

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

TOPICS
Scripting

Views

509

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 27, 2020 May 27, 2020

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
...

Votes

Translate

Translate
Community Expert ,
May 27, 2020 May 27, 2020

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 27, 2020 May 27, 2020

Copy link to clipboard

Copied

LATEST

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 )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines