//去除目錄文字藍色樣式以及文字下方藍色下划線
for(FieldStart field: (Iterable<FieldStart>)doc.getChildNodes(NodeType.FIELD_START, true)){
if (field.getFieldType() == FieldType.FIELD_HYPERLINK)
{
FieldHyperlink hyperlink = (FieldHyperlink)field.getField();
//判斷是否是目錄
if (hyperlink.getSubAddress() != null && hyperlink.getSubAddress().startsWith("_Toc")) {
//獲取目錄每行段落對象
Paragraph tocItem = (Paragraph)field.getAncestor(NodeType.PARAGRAPH);
if (tocItem != null) {
//設置每行目錄樣式
for (Run run : tocItem.getRuns()) {
run.getFont().setColor(Color.BLACK);
run.getFont().setBold(false);
run.getFont().setUnderline(Underline.NONE);
}
}
}
}
}