Skip to main content
Participant
May 30, 2025
Question

How can I fit a frame to its content using Python code to automate the process?

  • May 30, 2025
  • 3 replies
  • 474 views

My goal is to translate the original file (.indd) from English to Japanese. My Python code successfully translates the text and updates the fonts and language. However, I am encountering an issue where the translated text overflows the text frames (i.e., overset text).

Please advise if there’s any setting or attribute within the .idml file that can be updated using python code to automatically resize the text frame to fit the content.

Both original InDesign (.idml) and the Python-processed .idml file are attached for your reference.

3 replies

Community Expert
May 31, 2025

I exported out the IDML after applying Fit Frame to Content and then compared the spread xmls of the orginal IDML. I see differences in the path points of the textframe. That makes me believe that all this option does is resize the frame according to the current content, i.e. it is not a property of the frame but a change to dimensions.

However, if you apply "Auto-Size" from the textframe properties that sets the frame properties and making corresponding change in the IDML does remove the overset. Looking at your IDML I see the problem. You have added 

AutoSizingReferencePoint and AutoSizingType nodes as children of TextFramePreference node. However the correct format that works puts these as attributes of TextFramePreference node. See below
//This is from your IDML and does not work
<TextFramePreference TextColumnCount="1" TextColumnMaxWidth="0">
	<Properties>
		<InsetSpacing type="list">
			<ListItem type="unit">0</ListItem>
			<ListItem type="unit">0</ListItem>
			<ListItem type="unit">0</ListItem>
			<ListItem type="unit">0</ListItem>
		</InsetSpacing>
	</Properties>
<AutoSizingReferencePoint>TopLeftPoint</AutoSizingReferencePoint><AutoSizingType>HeightOnly</AutoSizingType></TextFramePreference>
//This works
<TextFramePreference TextColumnCount="1" TextColumnMaxWidth="0" AutoSizingType="HeightOnly" AutoSizingReferencePoint="TopLeftPoint">
	<Properties>
		<InsetSpacing type="list">
			<ListItem type="unit">0</ListItem>
			<ListItem type="unit">0</ListItem>
			<ListItem type="unit">0</ListItem>
			<ListItem type="unit">0</ListItem>
		</InsetSpacing>
	</Properties>
</TextFramePreference>

Attached the IDML I created

-Manan

-Manan
Community Expert
May 30, 2025

Hi @aparna_6212 ,

look up DOM documentation for ExtendScript. There are a lot of similarities between poperties there and IDML / IDMS.

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#TextFramePreference.html#d1e307842

 

Or look it up in IDMS files (Snippets) you export from InDesign text frames where all the necessary options are enabled.

 

Regards,
Uwe Laubender
( Adobe Community Expert )

 

 

 

Legend
May 30, 2025

Hi, 

 

Look for EnableTextFrameAutoSizingOptions.

 

P.

Participant
May 30, 2025

I tried adding Auto Size options to the XML files in the Spreads folder of the .idml, as shown below, but it didn’t work:

<TextFramePreference TextColumnCount="1" TextColumnFixedWidth="38.35039370078738" TextColumnMaxWidth="0">
<Properties>
<InsetSpacing type="list">
<ListItem type="unit">0</ListItem>
<ListItem type="unit">0</ListItem>
<ListItem type="unit">0</ListItem>
<ListItem type="unit">0</ListItem>
</InsetSpacing>
</Properties>
<AutoSizingReferencePoint>TopLeftPoint</AutoSizingReferencePoint><AutoSizingType>HeightOnly</AutoSizingType></TextFramePreference>