Update TOC (no other fields)

Hi,


I am trying to implement TOC update in the document generation/processing system. I use the following code to accomplish it.
document.updateFields();
document.updatePageLayout();

Unfortunately I found that some documents are now broken. I have some instances where hyperlinks are showing “according to 0” as opposed to previously “according to Appendix I” (just example that I have). This is something that I came across with. I cannot say what else can be affected and there is no way to check all the documents in the system. I assume it was caused by adding updateFields() to the existing code which caused update of all fields.

In my particular case I only want to support TOC. How can I achieve it? I want to update TOC and not force update of any other fields.

Thanks!
Hi Olga,

Thanks for your inquiry. Please use the following code example to update only TOC filed. Hope this helps you.

Document doc = new Document(MyDir + "in.docx");

for (Field field : doc.getRange().getFields())
{
if(field.getType() == FieldType.FIELD_TOC)
{
field.update();
break;
}
}

doc.save(MyDir + "Out v17.1.0.docx");