Change the Text Size in SmartArt Object when Creating It

I’m creating a SmartArt with some nodes that sometimes contain long text, so I would like to set the text size myself at the moment of the creation of the SmartArt or the SmartArtNode. Is this possible?

@ggg

To change the text size in a SmartArt when creating it, you can utilize the TextFrameFormat class to set the desired text properties, including font size. Here’s a general approach to achieve this:

  1. Create the SmartArt Shape: When you create a SmartArt shape, you can define its properties, including the text it will contain.

  2. Set Text Properties: After creating the SmartArt shape, you can access its TextFrameFormat to set the font size and other text-related properties.

Here’s a code example in Java that demonstrates how to create a SmartArt shape and set the text size:

import com.aspose.slides.ApiException;
import com.aspose.slides.model.Shape;
import com.aspose.slides.model.TextFrameFormat;
import com.aspose.slides.model.ParagraphFormat;
import com.aspose.slides.model.SolidFill;

public void createSmartArtWithCustomTextSize() throws ApiException {
    // Create a new SmartArt shape
    Shape smartArtShape = new Shape();
    smartArtShape.setShapeType(GeometryShape.ShapeTypeEnum.SMARTART);
    smartArtShape.setText("Your SmartArt Text Here");

    // Create and set TextFrameFormat
    TextFrameFormat textFrameFormat = new TextFrameFormat();
    textFrameFormat.setMarginLeft(2.0);
    textFrameFormat.setMarginRight(2.0);
    textFrameFormat.setMarginTop(2.0);
    textFrameFormat.setMarginBottom(2.0);
    
    // Set the font size
    ParagraphFormat paragraphFormat = new ParagraphFormat();
    SolidFill fillFormat = new SolidFill();
    fillFormat.setColor("#000000"); // Set text color
    paragraphFormat.setBulletFillFormat(fillFormat);
    textFrameFormat.setDefaultParagraphFormat(paragraphFormat);
    
    // Apply the TextFrameFormat to the SmartArt shape
    smartArtShape.setTextFrameFormat(textFrameFormat);

    // Now you can add the SmartArt shape to your slide
    // slide.getShapes().add(smartArtShape);
}

In this example, you create a SmartArt shape and set its text properties, including the font size through the TextFrameFormat. Adjust the margins and other properties as needed to fit your design requirements.

Make sure to replace "Your SmartArt Text Here" with the actual text you want to display in your SmartArt.

If you have any further questions or need additional examples, feel free to ask!

@ggg,
I need some time to answer your question. I will get back to you soon.

1 Like