Hi Team,
I want to add 2 bookmarks here to generate a table of content for two different sections.
Please help me to add separate bookmarks.
In the attached sample documents there are two separate tables of contents.
I want to add two different bookmarks for both the table of contents and also want to update that particular toc after insertion of bookmarks to the section.
Please find the attached sample document for reference.
Actual_generated_document.zip (40.6 KB)
I am able to insert one bookmark for the last section with the help of below code snippet.Its specific to TOC 2.
I want similar way to insert a bookmark for TOC 1.
It will be really helpful for me if you provide me the solution as soon as possible.
Document doc = new Document(“E:\Temp\Sample_documents\Actual_generated_document.docx”);
com.aspose.words.DocumentBuilder builder = new DocumentBuilder(doc);
builder.moveToDocumentEnd();
BookmarkStart bookmarkStart = builder.startBookmark(“bookmarked_Scope”);
builder.endBookmark(“bookmarked_Scope”);
doc.getLastSection().getBody().getFirstParagraph().insertBefore(bookmarkStart, doc.getLastSection().getBody().getFirstParagraph().getFirstChild());
for (Field field : doc.getLastSection().getBody().getRange().getFields()) {
if (field.getType() == FieldType.FIELD_TOC) {
FieldToc tocField = (FieldToc) field;
tocField.setBookmarkName(“bookmarked_Scope”);
tocField.update();
break;
}
}
doc.save(“E:\Temp\Sample_documents\awjava-20.3.docx”);