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. In this article, you will learn how to set gutter margins on the left edges of the page…


This content originally appeared on DEV Community and was authored by carlwils

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.

Import 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>

Sample 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);
    }
}

SetGutter


This content originally appeared on DEV Community and was authored by carlwils


Print Share Comment Cite Upload Translate Updates
APA

carlwils | Sciencx (2021-11-22T07:35:06+00:00) Java/ Set Gutter Margins in Word. Retrieved from https://www.scien.cx/2021/11/22/java-set-gutter-margins-in-word/

MLA
" » Java/ Set Gutter Margins in Word." carlwils | Sciencx - Monday November 22, 2021, https://www.scien.cx/2021/11/22/java-set-gutter-margins-in-word/
HARVARD
carlwils | Sciencx Monday November 22, 2021 » Java/ Set Gutter Margins in Word., viewed ,<https://www.scien.cx/2021/11/22/java-set-gutter-margins-in-word/>
VANCOUVER
carlwils | Sciencx - » Java/ Set Gutter Margins in Word. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/11/22/java-set-gutter-margins-in-word/
CHICAGO
" » Java/ Set Gutter Margins in Word." carlwils | Sciencx - Accessed . https://www.scien.cx/2021/11/22/java-set-gutter-margins-in-word/
IEEE
" » Java/ Set Gutter Margins in Word." carlwils | Sciencx [Online]. Available: https://www.scien.cx/2021/11/22/java-set-gutter-margins-in-word/. [Accessed: ]
rf:citation
» Java/ Set Gutter Margins in Word | carlwils | Sciencx | https://www.scien.cx/2021/11/22/java-set-gutter-margins-in-word/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.