Skip to main content
Inspiring
September 10, 2022
Answered

How to create TextFrame in document with Height and width alone using indesign javascript?

  • September 10, 2022
  • 3 replies
  • 419 views

I know to create textFrame with geometric bounds but I only have width and height as input for textFrame. Is there anyway to create it with only width and height or please suggest the possible way!

This topic has been closed for replies.
Correct answer rob day

Hi @Karthik SG , you could also wrap Peter‘s code in a function—here the parameters are x,y, width, height, destination page

 

 

 

 

var tframe = makeTextFrame(1,1,5,3,app.activeWindow.activePage)


/**
* Makes a new text frame on the active page 
* @ param x position 
* @ param y position
* @ param width
* @ param height
* @ param target page
* @ return the text frame 
*/
function makeTextFrame(x,y,w,h,p){
    return p.textFrames.add ({ geometricBounds: [y,x,y+h,x+w]});
}

 

 

 

3 replies

Community Expert
September 12, 2022

Hi @Karthik SG ,

you could add more property : value pairs to the object that is the only argument of method add().

Also note, that the frame is added to the first spread in your document, because no spread or page is specified.

And you could use strings for the measurement values and also mix them.

 

Sample code:

 

var propValueObject =
{
	geometricBounds :
		[
		"10 mm" , // y
		"10 mm" , // x
		"200 pt" , // y + height
		"100 pt" // x + width
		]
};

app.documents[0].textFrames.add( propValueObject );

 

Regards,
Uwe Laubender
( Adobe Community Professional )

rob day
Community Expert
rob dayCommunity ExpertCorrect answer
Community Expert
September 10, 2022

Hi @Karthik SG , you could also wrap Peter‘s code in a function—here the parameters are x,y, width, height, destination page

 

 

 

 

var tframe = makeTextFrame(1,1,5,3,app.activeWindow.activePage)


/**
* Makes a new text frame on the active page 
* @ param x position 
* @ param y position
* @ param width
* @ param height
* @ param target page
* @ return the text frame 
*/
function makeTextFrame(x,y,w,h,p){
    return p.textFrames.add ({ geometricBounds: [y,x,y+h,x+w]});
}

 

 

 

Peter Kahrel
Community Expert
Community Expert
September 10, 2022

Assuming four variables:

y: the frame's vertical position

x: the frame's horizontal position

width and height speak for themselves.

app.documents[0].textFrames.add ({
  geometricBounds: [y, x, y+height, x+width];
});/

 

Inspiring
September 12, 2022

Thanks Manan!