Document doc = new Document();
doc.loadFromFile("input.docx");
for (GridPitchType type : GridPitchType.values()) {
for (Object sec : doc.getSections()) {
((Section) sec).getPageSetup().setGridType(type);
((Section) sec).getPageSetup().setLinesPerPage(15);
}
doc.saveToFile("output.docx", FileFormat.Docx);
}
doc.close();