An Interest In:
Web News this Week
- March 20, 2024
- March 19, 2024
- March 18, 2024
- March 17, 2024
- March 16, 2024
- March 15, 2024
- March 14, 2024
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 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); }}
Original Link: https://dev.to/carlwils/java-set-gutter-margins-in-word-2cjb
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To