添加页码
public void addHeaderFooter(Document doc){
//创建页脚 页码
HeaderFooter footer = new HeaderFooter(doc, HeaderFooterType.FOOTER_PRIMARY);
doc.getFirstSection().getHeadersFooters().add(footer);
//页脚段落
Paragraph footerpara = new Paragraph(doc);
footerpara.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
Run footerparaRun = new Run(doc);
footerparaRun.getFont().setName("宋体");
footerparaRun.getFont().setSize(9.0);//小5号字体
footerpara.appendChild(footerparaRun);
footerpara.appendField(FieldType.FIELD_PAGE, true);//当前页码
footerpara.appendChild(footerparaRun);
footer.appendChild(footerpara);
}
生成目录
//将光标移到文档开始的位置
builder.moveToDocumentStart();
builder.insertBreak(BreakType.PAGE_BREAK);
//设置目录的格式
//“目录”两个字居中显示、加粗、搜宋体
builder.getC