設置word頁眉
/**
*
* @param document 文檔
* @param firstPageHeader 首頁頁眉
* @param primaryPageHeader 奇數(shù)頁眉
* @param evenPageHeader 偶數(shù)頁眉
* @author zhangxiong 2021-03-30 4:37 下午
* @return void
*/
public static void addPageSetup(Document document, String firstPageHeader,
String primaryPageHeader, String evenPageHeader) {
//創(chuàng)建DocumentBuilder
DocumentBuilder builder = new DocumentBuilder(document);
//設置移動到頁面最底下
// builder.moveToDocumentEnd();
//設置奇數(shù)頁和偶數(shù)頁頁眉頁腳
builder.getPageSetup().setOddAndEvenPagesHeaderFooter(true);
//設置除第一頁外的頁眉頁腳
builder.getPageSetup().setDifferentFirstPageHeaderFooter(true);
//設置字體
builder.getFont().setName("Arial");
builder.getFont().setBold(true);
builder.getFont().setSize(10);
//設置移動到頁眉和頁腳
// 首頁 頁眉
builder.moveToHeaderFooter(HeaderFooterType.HEADER_FIRST);
builder.write(firstPageHeader);
// 偶數(shù)頁 頁眉
builder.moveToHeaderFooter(HeaderFooterType.HEADER_EVEN);
builder.write(evenPageHeader);
// 奇數(shù)頁 頁眉
builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
builder.write(primaryPageHeader);
}