for (Field field : document.getRange().getFields()) {
int type = field.getType();
boolean isDeleteField = (type == FieldType.FIELD_TOC || type == FieldType.FIELD_TOC_ENTRY);
if (isDeleteField) {
field.remove();
}
}
Document doc = new Document("C:\\Temp\\in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
for (Field field : doc.getRange().getFields())
{
int type = field.getType();
boolean isDeleteField = (type == FieldType.FIELD_TOC || type == FieldType.FIELD_TOC_ENTRY);
if (isDeleteField)
{
builder.moveToField(field, true);
builder.writeln();
field.remove();
}
}
doc.save("C:\\Temp\\out.docx");