I am doing a merge of data from a google spreadsheet to a slides presentation using placeholder shapes and apps script, something along the lines of this example.
I have the merge working well. The first issue I am having though is that the text is not bound by the shape that contains it. If the text does not fit within the bounding shape it simply overflows:
That wouldn't be such a problem if I could then somehow tell programmatically that the text has overflowed. As far as I can tell though I can only get the height of the bounding shape. Which doesn't change even though it now "contains" text that covers a much greater height on the slide. I don't seem to be able to get the height of the actual text.
Is there any way to tell what the height of the textrange is, or that it has overflowed, so that I can then either adjust some feature of the text (the font size, or the length of the actual text, etc) so that the text is bound by the textbox? Or at least alert the user that the text has overflowed.
The PowerPoint equivalent of this would be textrange.boundheight if that helps describe the property I am looking for, with a similar property I would then hopefully be able to implement something similar to the AutoSize feature.
The merge of text to a slide without some way to fit the text to the placeholder shapes doesn't seem that useful to me.
As of January 2021, you can set auto fit setting in Google Slides editor.
When you click inside shape, you can see new Auto-fit setting, set to "Do not autofit" by default:
You can change it to "Shrink text on overflow":
Or another option: "Resize shape to fit text":
Update (July 2021): there new autofit
properties of Shape element:
autofitType
The autofit type of the shape. If the autofit type is
AUTOFIT_TYPE_UNSPECIFIED
, the autofit type is inherited from a parent placeholder if it exists. The field is automatically set toNONE
if a request is made that might affect text fitting within its bounding text box. In this case thefontScale
is applied to thefontSize
and thelineSpacingReduction
is applied to thelineSpacing
. Both properties are also reset to default values.
fontScale - readonly
The font scale applied to the shape. For shapes with
autofitType
NONE
orSHAPE_AUTOFIT
, this value is the default value of 1. ForTEXT_AUTOFIT
, this value multiplied by thefontSize
gives the font size that is rendered in the editor.
lineSpacingReduction - readonly
The line spacing reduction applied to the shape. For shapes with
autofitType
NONE
orSHAPE_AUTOFIT
, this value is the default value of 0. ForTEXT_AUTOFIT
, this value subtracted from thelineSpacing
gives the line spacing that is rendered in the editor.
P.S. autofitType
may be not marked as readonly in documentation, but there seems to be a bug which currently prevents an easy way to set it (to any other value than NONE
), see https://issuetracker.google.com/issues/189153562#comment5 and https://developers.google.com/apps-script/reference/slides/autofit (just getAutofitType()
available)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With