Java: Set Gutter Margins in Word

Gutter margins are designed to add extra space to the existing margins of a document, which ensures that the text of the document will not be obscured when binding. This is very useful when you need to bind some important official documents, books, or examination papers. This article will introduce how to set gutter margins on the left edges of the pages in a Word document using Spire.Doc for Java.

Install Spire.Doc for Java

First of all, you're required to add the Spire.Doc.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml file.

<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.doc</artifactId>
        <version>12.11.0</version>
    </dependency>
</dependencies>
    

Set Gutter Margins in Word

Although you can adjust the normal margins to add more space for document binding, setting gutter margins is a more efficient way to achieve the same function. The following are the steps to set gutter margins in a Word document:

  • Create a Document instance.
  • Load a Word document using Document.loadFromFile() method.
  • Get a specific section using Document.getSections().get() method.
  • Set gutter margin for that specified section using Section.getPageSetup().setGutter() method.
  • Save the document to file using Document.saveToFile() method.
  • Java
import com.spire.doc.*;
import java.io.IOException;

public class addGutter {
    public static void main(String[] args) throws IOException {
        //Create a Document instance
        Document document = new Document();

        //Load a sample Word document
        document.loadFromFile("input.docx");

        //Get the first section
        Section section = document.getSections().get(0);

        //Set gutter margin
        section.getPageSetup().setGutter(100f);

        //Save the file
        document.saveToFile("addGutter_output.docx", FileFormat.Docx);
    }
}

Java: Set Gutter Margins in Word

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.