Set Page Size and Page Orientation for Word Document Using Java

<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>
import com.spire.doc.*;
import com.spire.doc.documents.*;

public class WordPageSetup {
public static void main(String[] args) throws Exception {
//Load the sample document
Document doc= new Document();
doc.loadFromFile("Oscar Wilde.docx");
//Get the first section
Section section = doc.getSections().get(0);
//Set the page size
section.getPageSetup().setPageSize(PageSize.A3 );
//Set the page orientation
section.getPageSetup().setOrientation(PageOrientation.Landscape);
//Save the document to file
doc.saveToFile("PageSize.docx",FileFormat.Docx_2013);
}
}

--

--

--

Sharing Java Code

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Deploy Raspberry Pi Kubernetes cluster with Kubespray

Why your frontend repo is private?

Do You Know the Difference Between Git Merge and Git Rebase?

Libraries, Jet Fuel, and the Information Age

Vulnhub:infovore: 1 walkthrough!

How to Create Lambdas in AWS?

Data Fabric and Z Series-Part 3: Fuel your Machine Learning models with data on zSystems

Angular Videoconference app

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Andrew Wilson

Andrew Wilson

Sharing Java Code

More from Medium

Java: Add an Image Stamp to a Word Document

Introduction to Unit Testing with JUnit5

Building HTTP server (from scratch)

Database connectivity with java 🤯, using mysql…