Adjust the Header and Footer Distance in Word in Java

Adjust the Header and Footer Distance in Word in Java

2020-06-11 08:02:42 Written by  Koohji
Rate this item
(0 votes)

This article demonstrates how to adjust the header and footer distance in a Word document using Spire.Doc for Java.

import com.spire.doc.Document;
import com.spire.doc.FileFormat;
import com.spire.doc.Section;

public class AdjustHeaderFooterDistance {
    public static void main(String[] args){
        //Create a Document instance
        Document doc = new Document();
        //Load a Word document
        doc.loadFromFile("Headers and Footers.docx");

        //Get the first section
        Section section = doc.getSections().get(0);

        //Adjust the header distance
        section.getPageSetup().setHeaderDistance(100);

        //Adjust the footer distance
        section.getPageSetup().setFooterDistance(100);

        //Save the result document
        doc.saveToFile("Output.docx", FileFormat.Docx);
    }
}

Screenshot

Header:

Adjust the Header and Footer Distance in Word in Java

Footer:

Adjust the Header and Footer Distance in Word in Java

Additional Info

  • tutorial_title:
Last modified on Tuesday, 31 August 2021 09:20

Coupon Code Copied!

Christmas Sale

Celebrate the season with exclusive savings

Save 10% Sitewide

Use Code:

View Campaign Details