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

Free Support Forum - aspose.com

TOC update for HTML format

I have downloaded the latest Aspose.Words 9.0.0 in order to try out the new TOC update feature. This is a fantastic feature one that we have been waiting for with anticipation, it will certainly also add significant value for our customers.

Presently we build our reporting documents in memory with TOC and then save them in either doc, docx, html or pdf format as per user's requested format.

The TOC update works great for doc, docx, and pdf format.

However I am a little surprised by the result when I save in html format. At present it seems to result in page numbers as per doc/docx which are pointless when the document is a single page.

We had hoped that you would take an approach similar to microsoft. Convert the topics to links that navigate to the relevant section.

I have read the older posts relating to 'generating html with table of contents' as an alternative method of doing this but was hoping that this would somehow be included planned as part of the new TOC feature.

Therefore please confirm that the current behaviour is what you expected when using html format, and advise if there are any plans to improve this current approach. Alternatively can you advise on any better method for produng the MS word type html TOC using the new Apose TOC update feature.

Thanks

Daniel Finkelstein

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. As I can see, Aspose.Words produces almost the same TOC in HTML as MS Word does. The only difference is that page numbers in Aspose.Words TOC are not right aligned. Here is code I used for testing:

// Create DocumentBuilder, which we will use to generate document.

DocumentBuilder builder = new DocumentBuilder();

// At the beggining of the document we insert TOC filed, whick will be updated before saving document.

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

builder.Writeln();

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

builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;

builder.Writeln("Heading 1");

builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading2;

builder.Writeln("Heading 1.1");

builder.Writeln("Heading 1.2");

builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1;

builder.Writeln("Heading 2");

builder.Writeln("Heading 3");

builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading2;

builder.Writeln("Heading 3.1");

builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading3;

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.Write("Heading 3.3");

// Opdate fields in the document to update TOC.

builder.Document.UpdateFields();

// After updating fields only hyperlinks in TOC are updated,

// but page numbers are not updated.

// To update page numbes as well, we should call Document.UpdatePageLayout.

builder.Document.UpdatePageLayout();

// Now we can save the final document.

builder.Document.Save(@"Test001\out.html");

Would you please clarify, how you would like TOC should look in HTML. Maybe create simple example. This might help us to improve the behavior.

Best regards.

Thanks for quick reply.

A little further investigation using your code has helped me to clarify when the problem occurs

The reason I did not get any links when creating TOC and saving in html is becuase I did not include the '\h' option in my TOC definition if you change the following line in your code above then the same result is produced.

builder.InsertTableOfContents("\\o \"1-3\" \\z \\u");<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

I am not sure if you would consider this a problem but including this option solves this part of the problem.

The oustanding issue is that page numbers when loading a current 'docx' with a TOC, updating fields and then saving as an HTML do not update the page numbers as expected. I would expect all page numbers to be set ot 1 (there is only one page in Html format) rather than increased by 1. The following code adapted from your sample shows the issue.

// Create DocumentBuilder, which we will use to generate document.
Document doc = new Document(@"TestIn.docx");
DocumentBuilder builder = new DocumentBuilder(doc);

// Update fields in the document to update TOC.
builder.Document.UpdateFields();

// After updating fields only hyperlinks in TOC are updated,
// but page numbers are not updated.
// To update page numbes as well, we should call Document.UpdatePageLayout.
builder.Document.UpdatePageLayout();

// Now we can save the final document.
builder.Document.Save(@".\Testout.html");

I have also attached TestIn.docx and TestOut.html which are the input and output I receive when running the above code.

Thanks

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. Yes, you are right TOC is updated a little bit improperly. Your request has been linked to the appropriate issue. You will be notified as soon as it is resolved.

However, pages numbers in HTML should not be 1 for all TOC items. Numbers should be the same as in the original document. You should note that TOC is updated before saving the document so at the moment of updating you do not know in which format file will be saved.

Best regards.

The issues you have found earlier (filed as 15774) have been fixed in this update.


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