import com.spire.doc.*;
import com.spire.doc.documents.BreakType;
import com.spire.doc.documents.SectionBreakType;
public class AddPagebreakAndSectionbreak {
public static void main(String[] args){
//加載測試文檔
Document doc = new Document("test.docx");
Section sec= doc.getSections().get(0);
//插入分頁符
sec.getParagraphs().get(3).appendBreak(BreakType.Page_Break);
//插入分節符(4種情況)
sec.getParagraphs().get(8).insertSectionBreak(SectionBreakType.No_Break);//新節與前文内容連續,不從新一頁開始
//sec.getParagraphs().get(8).insertSectionBreak(SectionBreakType.New_Page);//新節從新一頁開始
//sec.getParagraphs().get(8).insertSectionBreak(SectionBreakType.Even_Page);//新節從偶數頁開始
//sec.getParagraphs().get(8).insertSectionBreak(SectionBreakType.Oddpage);//新節從奇數頁開始
//儲存文檔
doc.saveToFile("result.docx",FileFormat.Docx_2010);
}
}