Aspose TOC

HI, Need a clarification about TOC Table of content .
in my scenario Toc is not providing the proper page number.
Thanks.

Hi Saravana,

Thanks for contacting support.

Please share some details regarding the API you are using and also please share the code snippet and resource files so that we can test the scenario at our end.

Hi Nayyer,

Scenario : a document will be created first and saved in a directory. the same document will be read from the directory using Document Class
after that document will be fill with some content and Header & Footer also Updated. so that the page
will be increased in this scenario the page number of the first page and
the TOC is not get updated.

Please find the Attachment.

Thanks,
Saravana kumar.S

Hi ,
After updating the latest version of Aspose.word 14.8.0 , Table of content is not even show .

its provide a message like “Table of content is not available”

My code snipped,

public override VisitorAction VisitParagraphStart(Paragraph paragraph)
{
if (paragraph.Range.Text.Contains("<<$TOC$>>"))
{
paragraph.ParagraphFormat.Style.Font.Size = 13;
paragraph.ParagraphFormat.Style.Font.Name = "Arial";
paragraph.ParagraphFormat.Style.Font.Bold = false;
paragraph.ParagraphFormat.Style.Font.Italic = false;
paragraph.ParagraphFormat.LineSpacing = 12.0;

foreach(Run r in paragraph.Runs)
r.Text=r.Text == "<<$TOC$>>" ? " " : r.Text;

DocumentBuilder builder = new DocumentBuilder((Document)paragraph.Document);
builder.MoveTo(paragraph);

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


Please provide me a solution ASAP.

Thanks

Hi Saravana,

Thanks for your inquiry. It would be great if you please share following detail for investigation purposes.

  • Please attach your input Word document.
  • Please

create a standalone/runnable simple application (for example a Console
Application Project
) that demonstrates the code (Aspose.Words code) you used to generate
your output document

  • Please attach the output Word file that shows the undesired behavior.
  • Please attach your target Word document showing the desired behavior. You can use Microsoft Word to create your target Word document. I will investigate as to how you are expecting your final document be generated like.

Unfortunately,it is difficult to say what the problem is without the Document(s) and simplified application. We need your Document(s) and simple project to reproduce the problem. As soon as you get these pieces of information to us we’ll start our investigation into your issue.

Hi Tahir,

Please Find the Sample Project for TOC Issue.

Create a Document using this sample project and find the image how we are expecting the TOC Result, also there are some minor issues in this document.

My Input will be in HTML format.

Thanks.

Hi Saravana,

Thanks for sharing the detail. In your case, I suggest you please use the following highlighted code snippet to create to TOC formatting according to your requirements. You can update the TOC styles as shown in following code snippet. Hope this helps you. Please let us know if you have any more queries.

// Use a blank document
Document doc = new Document();
// Create a document builder to insert content with into document.
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert a table of contents at the beginning of the document.
builder.InsertTableOfContents("\\o \"1-3\" \\h \\z \\u");
// Start the actual document content on the second page.
builder.InsertBreak(BreakType.PageBreak);
// 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.Writeln("Heading 3.3");
doc.Styles[StyleIdentifier.Toc1].Font.Size = 12;
doc.Styles[StyleIdentifier.Toc1].Font.Bold = true;
doc.Styles[StyleIdentifier.Toc1].Font.Italic = true;
doc.Styles[StyleIdentifier.Toc2].Font.Size = 8;
doc.Styles[StyleIdentifier.Toc2].Font.Color = Color.Gray;
doc.Styles[StyleIdentifier.Toc3].Font.Size = 10;
doc.Styles[StyleIdentifier.Toc3].Font.Color = Color.Blue;
// Call the method below to update the TOC.
doc.UpdateFields();
doc.Save(MyDir + "Out.docx");

Hi Tahir,

Thanks for Your Code to format the TOC contend its working perfect, but still i had an issue in Page Number.

Please Check the Page Number of First page it remains with Page 1 of 3, But in Document there are nearly 15 pages are there and also in TOC Page is not updated properly.

i think this issue is because of Table in Html format, Inserting HTML to Builder.

private void CreateDocSections(List listSection, Document doc, DocumentBuilder builder, int pageIndex)
{
// Section protection only works when document protection is turned and only editing in form fields is allowed.
doc.Protect(ProtectionType.AllowOnlyFormFields);

for (var i = 0; i < listSection.Count; i++)
{
var newSec = new Aspose.Words.Section(doc);
if (pageIndex == 0)
newSec.PageSetup.SectionStart = SectionStart.Continuous;
else
{
if (i == 0)
newSec.PageSetup.SectionStart = SectionStart.NewPage;
else
newSec.PageSetup.SectionStart = SectionStart.Continuous;
}

doc.Sections.Add(newSec);
builder.MoveToSection(_countSectionIndex);
_countSectionIndex += 1;
if (listSection[i].Contains("<input name="hdnLandscape" type="hidden" value="MakeLandscape" />"))
{
newSec.PageSetup.Orientation = Orientation.Landscape;
builder.InsertHtml(listSection[i].Replace("<input name="hdnLandscape" type="hidden" value="MakeLandscape" />", ""));

}
else
{
newSec.PageSetup.Orientation = Orientation.Portrait;
builder.InsertHtml(listSection[i]);
}
}
}


if i update the document with out Table content its updating the Page number proper, please check the data with HTML.

Thanks

Hi Saravana,

Thanks for your inquiry. Please call Document.UpdateFields method before saving the final output document. This method updates the values of fields in the whole document.

When you open, modify and then save a document, Aspose.Words does not update fields automatically, it keeps them intact. Therefore, you would usually want to call this method before saving if you have modified the document programmatically and want to make sure the proper (calculated) field values appear in the saved document.

If you still face problem, please share following detail for investigation purposes.

  • Please attach your input HTML document.
  • Please

create a standalone/runnable simple application (for example a Console
Application Project
) that demonstrates the code (Aspose.Words code) you used to generate
your output document
As soon as you get these pieces of information to
us we’ll start our investigation into your issue.

Hi Tahir,

Thanks for your response. Please check the previous reply in that i have given sample project and Image.

In sample Project, we have used ckeditor to generate the html file.

for sample data please check this JS

\DynamicDocTemplate\javascripts\dynamicdoctemplate.js .

even i have used Document.UpdateFields in that sample project.

please check with table content in html, if i remove the table from html its working properly.

also please check with this

Converting from Word to PDF using Aspose.Word 14.4.0 Version

Thanks.

Hi Saravana,

Thanks for sharing the detail. I have tested the scenario and have managed to reproduce the same issues at my side. For the sake of correction, I have logged these problems in our issue tracking system as follow:

WORDSNET-10799 : Incorrect page numbers in TOC field
WORDSNET-10800 : Incorrect NUMPAGES value in footer of document

I have linked this forum thread to the same issues and you will be notified via this forum thread once these issues are resolved. We apologize for your inconvenience.

*saravana kumar:

also please check with this
Converting from Word to PDF using Aspose.Word 14.4.0 Version**

Your issue is pending for analysis
and is in the queue. We will update you via this forum thread once there
is any update available on this issue. Thank you for your patience.

Hi Tahir

Please let me know any updates is there for Above Issues.

Thanks,
Saravan kumar.S

Hi Saravana,

Thanks for your inquiry.

Unfortunately,
your issues are not resolved yet. Currently, your issues are pending for analysis and are in the queue. I am afraid, I can’t provide you any reliable estimate at the moment. Once your issue is analyzed, we will then be able to provide you an estimate.

Thank you for your patience and understanding.

Hi Tahir,

Thanks for your responses.

Please make Word to PDF conversion issue as High Priority, our clients are in urgent.

Thanks,

Hi Tahir,

Thanks for your responses.

Please make Word to PDF conversion issue as High Priority, our clients are in urgent.

Thanks,

Hi Saravana,

Thanks for your inquiry. I regret to share with you that your issue (WORDSNET-10800) has been postponed due to missing feature WORDSNET-832 (Make table layout as close to Word as possible) which is related to your issue.

After
the fix of WORDSNET-832, our development team will look into your
issue. I will be sure to inform you via this forum thread as soon as
this feature is available.

Regarding WORDSNET-10799, this issue is pending for analysis and is in the queue. However, I have requested our development team to share the ETA of this issue. As soon as any information is shared by them, I will be more than happy to share that with you.

We apologize for your inconvenience.

Hi Tahir,

Any Update regarding the Word to PDF conversion Issue,

Please let us know when will we get an update, so that we can convey to our client.

Thanks,
Saravana

Hi Saravana,

Thanks for your inquiry. I am afraid, we cannot provide you a reliable estimate at
the moment as you know the resolution of your issues are dependent on the implementation of another complex feature i.e.
WORDSNET-832. We will update you via this forum thread once there is any update available on your issues.

We apologize for your inconvenience.

Hi Tahir,

Please let me know the status of Word to PDF Conversion Issue, so that i can convey it to Client.

Thanks,
Saravana kumar.S

Hi Saravana,

Thanks for your inquiry. I regret to share with you that your issue is still postponed due to missing feature WORDSNET-832. We will update you via this forum thread once there is any update available on your issue.

We are really very sorry for your inconvenience.