@aolo23,
The following code does not reflect custom Font formatting to TOC entries.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
for (int i = 0; i < 20; i++)
builder.writeln();
Insert_TextBox_Headings(builder, StyleIdentifier.HEADING_1, doc.getFirstSection().getBody().getParagraphs().get(8),
72 * 2, 72 * 3, 72 * 3, 72);
Insert_TextBox_Headings(builder, StyleIdentifier.HEADING_2, doc.getFirstSection().getBody().getParagraphs().get(10),
72 * 2, 72 * 4, 72 * 3, 72);
Insert_TextBox_Headings(builder, StyleIdentifier.HEADING_3, doc.getFirstSection().getBody().getParagraphs().get(12),
72 * 2, 72 * 5, 72 * 3, 72);
Insert_TextBox_Headings(builder, StyleIdentifier.HEADING_4, doc.getFirstSection().getBody().getParagraphs().get(14),
72 * 2, 72 * 6, 72 * 3, 72);
builder.moveToDocumentStart();
builder.insertTableOfContents("\\o \\h \\z \\u ");
doc.updateFields();
doc.save("C:\\Temp\\awjava-21.2.docx");
public static void Insert_TextBox_Headings(DocumentBuilder document_builder, int style_Identifier, Paragraph para,
double left, double top, double width, double height) throws Exception {
document_builder.moveTo(para);
Shape textBox = document_builder.insertShape(ShapeType.TEXT_BOX, width, height);
textBox.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
textBox.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
textBox.setWrapType(WrapType.NONE);
textBox.setLeft(left);
textBox.setTop(top);
document_builder.moveTo(textBox.getFirstParagraph());
document_builder.getParagraphFormat().setStyleIdentifier(style_Identifier);
document_builder.getParagraphFormat().getStyle().getFont().setItalic(true);
document_builder.getFont().setItalic(true);
document_builder.writeln("Heading " + style_Identifier);
}
For the sake of any corrections in Aspose.Words API, we have logged this problem in our issue tracking system. The ID of this issue is WORDSNET-21941. We will further look into the details of this problem and will keep you updated on the status of linked issue. We apologize for your inconvenience.