//去除目录文字蓝色样式以及文字下方蓝色下划线
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);
}
}
}
}
}