Free Support Forum - aspose.com

TOC Issue about the text position

hi, I use the following code to generate the Index, but the H3,H4 .... don't work well. The attachment is the generated word file with wrong TOC.

DocumentBuilder builder = new DocumentBuilder();

// Get the document used by the DocumentBuilder.
Document doc = builder.Document;
List headlineList = doc.Lists.Add(ListTemplate.OutlineHeadingsLegal);

// Insrt a table of contents at the beginning of the document.
builder.InsertTableOfContents("\\o \"1-3\" \\h \\z \\u");

// Build a document with complex structure by applying different heading styles thus creating TOC entries.
builder.InsertBreak(BreakType.ParagraphBreak);

builder.ParagraphFormat.ClearFormatting();
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;
builder.ListFormat.List = headlineList;
builder.ListFormat.ListLevelNumber = 0;

builder.Writeln("Heading 1");

builder.ParagraphFormat.ClearFormatting();
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading2;
builder.ListFormat.List = headlineList;
builder.ListFormat.ListLevelNumber = 1;

builder.Writeln("Heading 1.1");
builder.Writeln("Heading 1.2");

builder.ParagraphFormat.ClearFormatting();
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;
builder.ListFormat.List = headlineList;
builder.ListFormat.ListLevelNumber = 0;

builder.Writeln("Heading 2");
builder.Writeln("Heading 3");

builder.ParagraphFormat.ClearFormatting();
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading2;
builder.ListFormat.List = headlineList;
builder.ListFormat.ListLevelNumber = 1;

builder.Writeln("Heading 3.1");

builder.ParagraphFormat.ClearFormatting();
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading3;
builder.ListFormat.List = headlineList;
builder.ListFormat.ListLevelNumber = 2;

builder.Writeln("Heading 3.1.1");
builder.Writeln("Heading 3.1.2");
builder.Writeln("Heading 3.1.3");

builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading2;

builder.Writeln("Heading 3.2");
builder.Writeln("Heading 3.3");

doc.UpdateFields();
doc.UpdatePageLayout();
doc.Save(MyDir + "DocumentBuilder.InsertToc Out.doc");

<!–[if gte mso 10]> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0pt 5.4pt 0pt 5.4pt; mso-para-margin:0pt; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman","serif";}

<![endif]–>

Hi

Thanks for your inquiry. I managed to reproduce the problem on my side. Your request has been linked to the appropriate issue. You will be notified as soon as it is resolved. As a workaround, you can try using the following code:

DocumentBuilder builder = new DocumentBuilder();

// Get the document used by the DocumentBuilder.

Document doc = builder.Document;

List headlineList = doc.Lists.Add(ListTemplate.OutlineHeadingsLegal);

// WORKAROUND: Problem with text position occurs because there are tabs.

// To work the problem around we can specify a whitespace as traling character.

foreach (ListLevel level in headlineList.ListLevels)

level.TrailingCharacter = ListTrailingCharacter.Space;

// Insrt a table of contents at the beginning of the document.

builder.InsertTableOfContents("\\o \"1-3\" \\h \\z \\u");

// Build a document with complex structure by applying different heading styles thus creating TOC entries.

builder.InsertBreak(BreakType.ParagraphBreak);

builder.ParagraphFormat.ClearFormatting();

builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;

builder.ListFormat.List = headlineList;

builder.ListFormat.ListLevelNumber = 0;

builder.Writeln("Heading 1");

builder.ParagraphFormat.ClearFormatting();

builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading2;

builder.ListFormat.List = headlineList;

builder.ListFormat.ListLevelNumber = 1;

builder.Writeln("Heading 1.1");

builder.Writeln("Heading 1.2");

builder.ParagraphFormat.ClearFormatting();

builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;

builder.ListFormat.List = headlineList;

builder.ListFormat.ListLevelNumber = 0;

builder.Writeln("Heading 2");

builder.Writeln("Heading 3");

builder.ParagraphFormat.ClearFormatting();

builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading2;

builder.ListFormat.List = headlineList;

builder.ListFormat.ListLevelNumber = 1;

builder.Writeln("Heading 3.1");

builder.ParagraphFormat.ClearFormatting();

builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading3;

builder.ListFormat.List = headlineList;

builder.ListFormat.ListLevelNumber = 2;

builder.Writeln("Heading 3.1.1");

builder.Writeln("Heading 3.1.2");

builder.Writeln("Heading 3.1.3");

builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading2;

builder.Writeln("Heading 3.2");

builder.Writeln("Heading 3.3");

doc.UpdateFields();

doc.UpdatePageLayout();

doc.Save(@"Test001\out.doc");

Hope this helps.

Best regards,

thanks a lot, it works well.

The issues you have found earlier (filed as 17406) have been fixed in this .NET update and in this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(1)