Manage SmartArt
Get Text from 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();
}
}
Change Layout Type of 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 {
// Add SmartArt BasicProcess
var smart = pres.getSlides().get_Item(0).getShapes().addSmartArt(10, 10, 400, 300, aspose.slides.SmartArtLayoutType.BasicBlockList);
// Change LayoutType to BasicProcess
smart.setLayout(aspose.slides.SmartArtLayoutType.BasicProcess);
// Saving Presentation
pres.save("ChangeSmartArtLayout_out.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
if (pres != null) {
pres.dispose();
}
}
Check Hidden Property of 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 {
// Add SmartArt BasicProcess
var smart = pres.getSlides().get_Item(0).getShapes().addSmartArt(10, 10, 400, 300, aspose.slides.SmartArtLayoutType.RadialCycle);
// Add node on SmartArt
var node = smart.getAllNodes().addNode();
// Check isHidden property
var hidden = node.isHidden();// Returns true
if (hidden) {
// Do some actions or notifications
}
// Saving Presentation
pres.save("CheckSmartArtHiddenProperty_out.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
if (pres != null) {
pres.dispose();
}
}
Get or Set Organization Chart Type
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:
- Create an instance of Presentation class.
- Add SmartArt on slide.
- Get or set the organization chart type.
- 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 {
// Add SmartArt BasicProcess
var smart = pres.getSlides().get_Item(0).getShapes().addSmartArt(10, 10, 400, 300, aspose.slides.SmartArtLayoutType.OrganizationChart);
// Get or Set the organization chart type
smart.getNodes().get_Item(0).setOrganizationChartLayout(aspose.slides.OrganizationChartLayoutType.LeftHanging);
// Saving Presentation
pres.save("OrganizeChartLayoutType_out.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
if (pres != null) {
pres.dispose();
}
}
Create Picture Organization Chart
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:
- Create an instance of the Presentation class.
- Obtain a slide’s reference by its index.
- Add a chart with default data along with the desired type (ChartType.PictureOrganizationChart).
- 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();
}
}
Get or Set SmartArt State
In order to change the layout type of SmartArt. Please follow the steps below:
- Create an instance of the Presentation class.
- Add SmartArt on slide.
- Get or Set the state of SmartArt Diagram.
- Write the presentation as a PPTX file.
The following code is used to create a chart.
// Instantiate Presentation class that represents the PPTX file
var pres = new aspose.slides.Presentation();
try {
// Add SmartArt BasicProcess
var smart = pres.getSlides().get_Item(0).getShapes().addSmartArt(10, 10, 400, 300, aspose.slides.SmartArtLayoutType.BasicProcess);
// Get or Set the state of SmartArt Diagram
smart.setReversed(true);
var flag = smart.isReversed();
// Saving Presentation
pres.save("output.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
if (pres != null) {
pres.dispose();
}
}