Set Paragraph Indentation for Word Document using Java

<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>http://repo.e-iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.doc.free</artifactId>
<version>3.9.0</version>
</dependency>
</dependencies>
import com.spire.doc.*;
import com.spire.doc.documents.*;

public class WordparaIndent {
public static void main(String[] args) {

//load the sample document
Document document= new Document();
document.loadFromFile("C:\\Users\\Administrator\\Desktop\\input.docx");

Section section = document.getSections().get(0);

//get the second paragraph and set the left indent
Paragraph para1 = section.getParagraphs().get(1);
para1.getFormat().setLeftIndent(30);

//get the third paragraph and set the right indent
Paragraph para2 = section.getParagraphs().get(2);
para2.getFormat().setRightIndent(30);

//get the fourth paragraph and set the first line indent
Paragraph para3 = section.getParagraphs().get(3);
para3.getFormat().setFirstLineIndent(40);

//save the document to file
document.saveToFile("WordIndent.docx", FileFormat.Docx_2013);

}
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store