- Code: Select all
documentPart.getContents().getBody().getContent().add(2, getTocParaUsingDocx4j());
However, I am not able to add TOC in second page?
documentPart.getContents().getBody().getContent().add(2, getTocParaUsingDocx4j());
jason wrote:What is getTocParaUsingDocx4j() ?!?
public P getTocParaUsingDocx4j(){
P paragraphForTOC = objectFactory.createP();
R r = objectFactory.createR();
FldChar fldchar = objectFactory.createFldChar();
fldchar.setFldCharType(STFldCharType.BEGIN);
fldchar.setDirty(true);
r.getContent().add(getWrappedFldChar(fldchar));
paragraphForTOC.getContent().add(r);
R r1 = objectFactory.createR();
Text txt = new Text();
txt.setSpace("preserve");
txt.setValue("TOC \\o \"1-3\" \\h \\z \\u \\h");
r.getContent().add(objectFactory.createRInstrText(txt) );
paragraphForTOC.getContent().add(r1);
FldChar fldcharend = objectFactory.createFldChar();
fldcharend.setFldCharType(STFldCharType.END);
R r2 = objectFactory.createR();
r2.getContent().add(getWrappedFldChar(fldcharend));
paragraphForTOC.getContent().add(r2);
return paragraphForTOC;
}
<div id="toc">
<p>Table Of Contents</p>
</div>
#toc {-fs-page-sequence: start;page-break-after: always;page-break-before: always;}
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());
}
This document contains fields that may refer ....
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.
Since your getTocParaUsingDocx4j method doesn't add the ToC content control, the Enterprise ToC update code won't have done anything.
Toc.setTocHeadingText("Table Of Contents");
TocGenerator.generateToc(wordMLPackage, 5,"TOC \\o \"3-3\" \\h \\z \\u \\h \"Title,1,Heading 1,1,Heading 2,3,Appendix 1,1,Appendix 2,2,Unnumbered Heading,1,h1,1,h2,3\" ", false);
If it isn't 3.1.0.5, please try that, from http://www.plutext.com/dn/downloads/140 ... -trial.zip
Users browsing this forum: No registered users and 28 guests