Java set page margins and page borders for word document

The following code snippets demonstrate how to use Spire.Doc for Java to set the page margins and page borders for word document in Java applications.

import com.spire.doc.*;
import com.spire.doc.documents.*;

public class PageSetup{
    public static void main(String[] args) throws Exception{

            String inputFile="Sample.docx";
            String outputFile="out/result.docx";

            //load a word document
            Document document= new Document(inputFile);

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

            //set the page margins
            section.getPageSetup().getMargins().setTop(30f);
            section.getPageSetup().getMargins().setBottom(30f);
            section.getPageSetup().getMargins().setLeft(60f);
            section.getPageSetup().getMargins().setRight(80f);

            //set the boarder type and color
            section.getPageSetup().getBorders().setBorderType(BorderStyle.Double_Wave);
            section.getPageSetup().getBorders().setColor(java.awt.Color.blue);

            //set the space between the border and text
            section.getPageSetup().getBorders().getTop().setSpace(20);
            section.getPageSetup().getBorders().getBottom().setSpace(30);
            section.getPageSetup().getBorders().getLeft().setSpace(30);
            section.getPageSetup().getBorders().getRight().setSpace(25);

            //save the file
            document.saveToFile(outputFile, FileFormat.Docx);
        }

    }

Effective screenshot after setting the page margins and page borders for the word document:

Java set page margins and page borders for word document