We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

TOC descrepancies : Mixing the Header and Page Number (if header is less than 5 chars)

Issue 1

=========================

I am adding TOC to the document being generated. TOC is updated fine. But if the Header items in TOC are short , say less than 5 chars then the Header and Page number are getting merged.Please find the attached document (document.docx) for example.In the TOC : If you see the "Fees" it displays as "Fees7" , along with the page number. For other Headers it is working fine. If i add one more char to Fees then it is aligned properly.

My Code is as below:

builder.ParagraphFormat.StyleName = "Contents title";

builder.Writeln("Contents");

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

==========================

Issue 2

There is lot of space that is being occupied after "Contents" ... i.e .. between "contents" and TOC.

and also after TOC, there is much space occupied. Is there a way to cut this space? Also will it be possible to decrease the space between each header in the TOC?

Thanks in advance.

Hi

Thanks for your request. As I can see the document you attached was not generated by Aspose.Words or was post-processed by some other tool. TOC in your document is inserted in some strange way. First of all it is inserted into a frame. Since Aspose.Words does not allow creating frames programmatically, I do not think the TOC in your document was inserted using Aspose.Words.

The second issue is also related to the fact that TOC is inside text frame.

It would be great if you attach your source document and sample code that will allow us to generate the same document on our side. We will check the issue and provide you more information.

Best regards,

Attached the document generated by using Aspose unedited. Please find the attachment "Document_UnEdited.docx". Earlier document was edited by me (removed some parts of it).

Also here is the actual code:

Document doc = new Document(mainStream);
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToDocumentEnd();
builder.ParagraphFormat.StyleName = "Contents title";
builder.Writeln("Contents");
builder.InsertTableOfContents("\\o \"1-1\" \\h \\z \\u");

builder.StartTable();
// Here goes the code of building the content of the document with question .. answers etc ...

doc.UpdateFields();
doc.Save(Response, "Document.docx", ContentDisposition.Attachment, null);

Hi Jagadish,

Thank you for additional information. But could please also attach your input document for testing?

Also, as I can see MS Word also updates TOC in this frame incorrectly. I think, you can resolve the problem by avoiding using frames in your document and use a simple bookmarks as a placeholder for TOC.

Best regards,

Hi Alexey,

Please find the attached source document "MainTemplate_Source.docx".

I am exclusively writing any code to use frames, I am just using "builder.InsertTableOfContents("\\o \"1-1\" \\h \\z \\u");" to inser TOC into the document.

It seems it is inserting the TOC in a frame in the generated document. Is there anything that i should change in that code to use simple bookmarks as a placeholder for TOC?

Does the fix goes in code or Formatting the MainTemplate_Source.docx?

Thanks in advance

Hi

Thank you for additional information. I investigated your template and found that TOC1…TOC9 styles are configured to be a frame. That is why after updating TOC it is inside a frame. By the way, Ms Word also updates TOC the same way as Aspose.Words does. So the only way I can suggest you to resolve this problem is changing TOC1…TOC9 styles in your template.

Best regards,

Hi Alexey,

Thanks for the information. I understand that it is th TOC style that i have to change.

I have tried many ways (By removing the frame from TOC1.. etc ..), but couldnt figure out how to do it. We highly appreciate if you give me instructions for editing the style of TOC.... in the template to avoid this issue.

Thanks in advance

More information :

still the small Words like "Fees" are mixed with Page number.

I am again attaching the MainTemplate & Generated_Document.docx (generated by Aspose using the MainTemplate.docx.

Please take a look in TOC of Generated_Document.docx for "Fees13".

Hi

Thanks for your request. To remove frame format form the styles, you should do the following:

  • Select TOC1…TOCN style
  • Click modify
  • At the bottom of the dialog click “Format” and select “Frame”
  • In the dialog click “Remove Frame”

Except frame format you should also remove paragraphs indentation to resolve the problem with “Fees”. Please see the attached screenshot.

Hope this helps.

Best regards,

It Worked!

Thanks. Really appreciate your skills and prompt reply.