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

Free Support Forum - aspose.com

Epub creation - table of contents are not linked in generated epub

I am generating epubs from various word documents and notice that the table of contents in the epub are not linked.

Is there an option in Aspose.Words to generate epubs with table of contents that are linked?

Attached is a sample docx file with a table of content and the converted epub
Thanks in advance.

Hi Brian,

Thanks for interest in Aspose.

I believe to get the contents linking like this you need to add the "\h" switch to your TOC.

You can achieve this by:

  1. Opening your document in MS Word
  2. Toggling field codes by pressing ALT+F9
  3. Adding the "\h" switch in your TOC field after the "\u" switch.
  4. Adding the lines doc.UpdateFields(), doc.UpdatePagelayout() to your code if they are not already there, before you saved your document.

If you have any other queries please feel free to ask.

Thanks,

Thank you for the prompt reply.


Unfortunately I don’t have control of the source documents.
Can altering of the source document be done pro-grammaticality?




Hi

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

Thanks for your inquiry. You can modify filed code of TOC field programmatically. You can use the same technique as described here:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/howto-rename-merge-fields.html

But in your case you will work with TOC fields, and not with MERGEFIELS. Hope this helps. Please let us know if you need more assistance, we will be glad to help you.

Best regards.

I am able to create TOC with links however the TOC is duplicated.
Using the same docx file.
Attached is a screen shot of the issue...TOC duplication.JPG
Also attached is my modified class (created from the above link)...toc class.cs

Not sure what I am doing incorrect. Please help. Thanks in advance.

using this code to convert...
Document doc = new Document(_sourceFilePath);
NodeCollection fieldStarts = doc.GetChildNodes(NodeType.FieldStart, true, false);
foreach (FieldStart fieldStart in fieldStarts)
{
if (fieldStart.FieldType.Equals(FieldType.FieldTOC))
{
TOC toc = new TOC(fieldStart);
toc.Name = toc.Name + @"\u";
}
}

doc.UpdateFields();
doc.UpdatePageLayout();
doc.Save(_destinationFilePath, SaveFormat.Epub);

Hi Brian,

Thanks for your inquiry.

It seems the method of updating the field code using the field result does not work as expected for the TOC field. The current code does not completely remove the TOC text and some unlinked runs still remain causing there to appear to be two TOCs.

Instead I suggest just updating the field code itself and then letting the UpdateFields method handle this.

I have attached the the reworked class to this post.

Thanks,