I could generate TOC in appropriate page.
- I first added a Div element in my HTML page with style
- Code: Select all
<div id="toc">
<p>Table Of Contents</p>
</div>
#toc {-fs-page-sequence: start;page-break-after: always;page-break-before: always;}
And then in my java code:
- Code: Select all
String xpath = "//w:r[w:t[contains(text(),'Table Of Contents')]]";
List<Object> list = documentPart.getJAXBNodesViaXPath(xpath, true);
for(Object obj : list){
R r = (R)obj;
P p = (P)r.getParent();
p.getContent().add(getTocParaUsingDocx4j());
}
Though this solved my problem, but when I open word document I get a dialog with following message
- Code: Select all
This document contains fields that may refer ....
Any solution to this dialog?
I also tried plutext's enterprise version. Though TOC was generated without any issue, but when I refresh TOC manually in word document, TOC is replaced by following text
- Code: Select all
Table Of Contents
Word did not find any entries for your table of contents.
In your document, select the words to include in the table of contents, and then on the Home tab, under Styles, click a heading style. Repeat for each heading that you want to include, and then insert the table of contents in your document. To manually create a table of contents, on the Document Elements tab, under Table of Contents, point to a style and then click the down arrow button. Click one of the styles under Manual Table of Contents, and then type the entries manually.
I am still clueless when should I try further with plutext's solution or look for alternative. Any suggestion?