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. In this article, you will learn how to set gutter margins on the left edges of the pages in a Word document using a free Java API.
PermalinkImport JAR Dependency of the Free API
Method 1: Download the free API (Free Spire.Doc for Java) and unzip it. Then add the Spire.Doc.jar file to your Java application as dependency.
Method 2: You can also add the jar dependency to maven project by adding the following configurations to the pom.xml.
<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>
PermalinkSample Code
The methods offered by Free Spire.Doc for Java allows you to set gutter margins in a Word document, and the detailed steps are as follows:
● 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.
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("test.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);
}
}