Adjust the Header and Footer Distance in Word in Java

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