Java set paragraph indentation for word document

The following code snippets demonstrate how to indent paragraphs for Word document in Java applications. With the help of Spire.Doc for Java, developers can set the paragraph indentation easily. There are four kinds of paragraph indentation style for word document: Left Indentation, Right Indentation, First Line Indentation and Hanging Indentation.

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();

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

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

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

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

        //get the fifth paragraph and set the hanging indent
        Paragraph para4 = section.getParagraphs().get(4);
        //save the document to file
        document.saveToFile("out/WordIndent.docx", FileFormat.Docx_2013);


Effective screenshot after setting the word indentation styles for word paragraph:

Java set paragraph indentation for word document