Java set the page size and page orientation for Word

The following code snippets demonstrate how to use Spire.Doc for Java to set the page size and page orientation for word document in Java applications.

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("Sample.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("Result.docx",FileFormat.Docx_2013);
    }
}

Effective screenshot:

Java set the page size and page orientation for Word