该文将详细介绍如何使用Spire.Presentation for Java设置幻灯片段落的缩进样式与间距。
import com.spire.presentation.*;
public class IndentStyle {
public static void main(String[] args) throws Exception{
//加载示例文档
Presentation presentation = new Presentation();
presentation.loadFromFile("Sample.pptx");
//获取幻灯片图形
IAutoShape shape = (IAutoShape) presentation.getSlides().get(0).getShapes().get(0);
//设置第一个段落首行缩进和间距
shape.getTextFrame().getParagraphs().get(0).setIndent(20);
shape.getTextFrame().getParagraphs().get(0).setLeftMargin(10);
shape.getTextFrame().getParagraphs().get(0).setSpaceAfter(10);
//设置第三个段落悬挂缩进和间距
shape.getTextFrame().getParagraphs().get(2).setIndent(-100);
shape.getTextFrame().getParagraphs().get(2).setLeftMargin(40);
shape.getTextFrame().getParagraphs().get(2).setSpaceBefore(0);
shape.getTextFrame().getParagraphs().get(2).setSpaceAfter(0);
//保存文档
String output = "output/indent.pptx";
presentation.saveToFile(output, FileFormat.PPTX_2010);
}
}
效果图: