A gutter margin is used to add extra space to the side, top margin, or inside margins of a document you plan to bind. That helps ensure that text cannot be obscured while binding. This article will show you how to set gutter margins for a Word document using Java codes.
DEPENDENCY
First of all, you’re required to get the package of Free Spire.Doc for Java from this link, and then manually add Spire.Doc.jar to your Java program. Or if you use Maven, just type the following codes in the pom.xml file to import the JAR 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.free</artifactId>
<version>5.1.0</version>
</dependency>
</dependencies>
USING THE CODE
Free Spire.Doc for Java offers the Section.getPageSetup().setGutter() method to set gutter margins for a Word document. The detailed steps are listed below.
l Create a Document instance.
l Load a Word document
using Document.loadFromFile()
method.
l Get a specific section
using Document.getSections().get() method.
l Set gutter margins for
the specified section using Section.getPageSetup().setGutter()
method.
l Save the document to another
file using Document.saveToFile() method.
import com.spire.doc.*;
public class AddGutterMargin {
public static void main(String[] args) {
//Create a Document instance
Document document = new Document();
//Load a sample Word document
document.loadFromFile("C:\\Users\\Test1\\Desktop\\Sample.docx");
//Get the first section
Section section = document.getSections().get(0);
//Set gutter margin
section.getPageSetup().setGutter(100f);
//Save the file
document.saveToFile("output/addGutterMargin.docx", FileFormat.Docx);
}
}
No comments:
Post a Comment