Hi Smitha,
Thanks for your inquiry. Please use the following code snippet to set the TOC TabLeader.
Document doc = new Document(MyDir + "double-byte.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
builder.moveToDocumentStart();
builder.insertTableOfContents("\\o \"1-3\" \\h \\z \\u");
// To demonstate the technique let's configure the first 4 levels of TOC.
Style toc1 = doc.getStyles().getByStyleIdentifier(StyleIdentifier.TOC_1);
Style toc2 = doc.getStyles().getByStyleIdentifier(StyleIdentifier.TOC_2);
Style toc3 = doc.getStyles().getByStyleIdentifier(StyleIdentifier.TOC_3);
Style toc4 = doc.getStyles().getByStyleIdentifier(StyleIdentifier.TOC_4);
Style[] tocStyles = { toc1, toc2, toc3, toc4 };
for (Style style : tocStyles)
{
style.getParagraphFormat().getTabStops().clear();
style.getParagraphFormat().getTabStops().add(500, TabAlignment.RIGHT, TabLeader.LINE);
}
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
pdfSaveOptions.setSaveFormat(SaveFormat.PDF);
OutlineOptions outline = pdfSaveOptions.getOutlineOptions();
outline.setHeadingsOutlineLevels(5);
doc.updateFields();
doc.save(MyDir + "Out.pdf", pdfSaveOptions);
I like to share some more detail about issue WORDSNET-8217. Your document contains the content control (STRUCTURED_DOCUMENT_TAG) at the start of document. The DocumentBuilder.moveToDocumentStart moves the cursor inside the content control. When you insert section break inside contents control, this moves the TOC field contents to page number 4. This is a bug (WORDSNET-8217).
You can use the code shared in my last post to achieve your requirements. Regarding your second query about bookmarks, it would be great if you please share some more detail about this query. I will investigate the issue on my side and provide you more information.