Gestionar SmartArt

Obtener texto de SmartArt

Now TextFrame method has been added to SmartArtShape class and SmartArtShape class respectively. This property allows you to get all text from SmartArt if it has not only nodes text. The following sample code will help you to get text from SmartArt node.

var pres = new aspose.slides.Presentation("Presentation.pptx");
try {
    var slide = pres.getSlides().get_Item(0);
    var smartArt = slide.getShapes().get_Item(0);
    var smartArtNodes = smartArt.getAllNodes();
    
    for (let i = 0; i < smartArtNodes.size(); i++) {
        const smartArtNode = smartArtNodes.get_Item(i);
        for (let j = 0; j < smartArtNode.getShapes().size(); j++) {
            const nodeShape = smartArtNode.getShapes().get_Item(j);
            if (nodeShape.getTextFrame() != null) {
                console.log(nodeShape.getTextFrame().getText());
            }
        }
    }
    
} finally {
    if (pres != null) {
        pres.dispose();
    }
}

Cambiar tipo de diseño de SmartArt

In order to change the layout type of SmartArt. Please follow the steps below:

  • Create an instance of Presentation class.
  • Obtain the reference of a slide by using its Index.
  • Add SmartArt BasicBlockList.
  • Change LayoutType to BasicProcess.
  • Write the presentation as a PPTX file. In the example given below, we have added a connector between two shapes.
var pres = new aspose.slides.Presentation();
try {
    // Agregar SmartArt BasicProcess
    var smart = pres.getSlides().get_Item(0).getShapes().addSmartArt(10, 10, 400, 300, aspose.slides.SmartArtLayoutType.BasicBlockList);
    // Cambiar LayoutType a BasicProcess
    smart.setLayout(aspose.slides.SmartArtLayoutType.BasicProcess);
    // Guardar presentación
    pres.save("ChangeSmartArtLayout_out.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
    if (pres != null) {
        pres.dispose();
    }
}

Comprobar la propiedad oculta de SmartArt

Please note: method SmartArtNode.isHidden() returns true if this node is a hidden node in the data model. In order to check the hidden property of any node of SmartArt. Please follow the steps below:

  • Create an instance of Presentation class.
  • Add SmartArt RadialCycle.
  • Add node on SmartArt.
  • Check isHidden property.
  • Write the presentation as a PPTX file.

In the example given below, we have added a connector between two shapes.

var pres = new aspose.slides.Presentation();
try {
    // Agregar SmartArt BasicProcess
    var smart = pres.getSlides().get_Item(0).getShapes().addSmartArt(10, 10, 400, 300, aspose.slides.SmartArtLayoutType.RadialCycle);
    // Agregar nodo en SmartArt
    var node = smart.getAllNodes().addNode();
    // Comprobar la propiedad isHidden
    var hidden = node.isHidden();// Devuelve true
    if (hidden) {
        // Realizar algunas acciones o notificaciones
    }
    // Guardar presentación
    pres.save("CheckSmartArtHiddenProperty_out.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
    if (pres != null) {
        pres.dispose();
    }
}

Obtener o establecer el tipo de organigrama

Methods SmartArtNode.getOrganizationChartLayout() , setOrganizationChartLayout(int) allow get or sets organization chart type associated with current node. In order to get or set organization chart type. Please follow the steps below:

var pres = new aspose.slides.Presentation();
try {
    // Agregar SmartArt BasicProcess
    var smart = pres.getSlides().get_Item(0).getShapes().addSmartArt(10, 10, 400, 300, aspose.slides.SmartArtLayoutType.OrganizationChart);
    // Obtener o establecer el tipo de organigrama
    smart.getNodes().get_Item(0).setOrganizationChartLayout(aspose.slides.OrganizationChartLayoutType.LeftHanging);
    // Guardar presentación
    pres.save("OrganizeChartLayoutType_out.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
    if (pres != null) {
        pres.dispose();
    }
}

Crear organigrama de imagen

Aspose.Slides for Node.js via Java provides a simple API for creating and PictureOrganization charts in an easy way. To create a chart on a slide:

  1. Create an instance of the Presentation class.
  2. Obtain a slide’s reference by its index.
  3. Add a chart with default data along with the desired type (ChartType.PictureOrganizationChart).
  4. Write the modified presentation to a PPTX file

The following code is used to create a chart.

var pres = new aspose.slides.Presentation("test.pptx");
try {
    var smartArt = pres.getSlides().get_Item(0).getShapes().addSmartArt(0, 0, 400, 400, aspose.slides.SmartArtLayoutType.PictureOrganizationChart);
    pres.save("OrganizationChart.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
    if (pres != null) {
        pres.dispose();
    }
}

Obtener o establecer el estado de SmartArt

In order to change the layout type of SmartArt. Please follow the steps below:

  1. Create an instance of the Presentation class.
  2. Add SmartArt on slide.
  3. Get or Set the state of SmartArt Diagram.
  4. Write the presentation as a PPTX file.

The following code is used to create a chart.

// Instanciar la clase Presentation que representa el archivo PPTX
var pres = new aspose.slides.Presentation();
try {
    // Agregar SmartArt BasicProcess
    var smart = pres.getSlides().get_Item(0).getShapes().addSmartArt(10, 10, 400, 300, aspose.slides.SmartArtLayoutType.BasicProcess);
    // Obtener o establecer el estado del diagrama SmartArt
    smart.setReversed(true);
    var flag = smart.isReversed();
    // Guardar la presentación
    pres.save("output.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
    if (pres != null) {
        pres.dispose();
    }
}

FAQ

¿SmartArt admite reflejo/inversión para idiomas RTL?

Yes. The setReversed method switches the diagram direction (LTR/RTL) if the selected SmartArt type supports reversal.

¿Cómo puedo copiar SmartArt a la misma diapositiva o a otra presentación manteniendo el formato?

You can clone the SmartArt shape via the shapes collection (ShapeCollection.addClone) or clone the entire slide containing this shape. Both approaches preserve size, position, and styling.

¿Cómo renderizo SmartArt a una imagen raster para vista previa o exportación web?

Render the slide (or the whole presentation) to PNG/JPEG through the API that converts slides/presentations to images—SmartArt will be drawn as part of the slide.

¿Cómo puedo seleccionar programáticamente un SmartArt específico en una diapositiva si hay varios?

A common practice is to use alternative text (Alt Text) or setName and search for the shape by that attribute using Slide.getShapes, then check the type to confirm it’s SmartArt. The documentation describes typical techniques for finding and working with shapes.