@Amruthajo I’m not able to reproduce the issue that you mention. I’m using the Package with version 23.1.0 (so, please try updating the version) and the following code:
// Initialize document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("TABLE OF CONTENTS");
// Insert a table of contents at the beginning of the document.
builder.InsertTableOfContents("\\o \"1-2\" \\h \\z \\u");
// Build a document with complex structure by applying different heading styles thus creating TOC entries.
for (int i = 1; i <= 100; i++)
{
// Inserting data which is a HTML
if(i%2 == 0)
{
builder.InsertHtml($"<h2>HEADER 2 COUNT {i}</h2>");
}
else if(i%3 == 0)
{
builder.InsertHtml($"<h3>HEADER 3 COUNT {i}</h3>");
}
else
{
builder.InsertBreak(BreakType.PageBreak);
builder.InsertHtml($"<h1>HEADER 1 COUNT {i}</h1>");
}
builder.InsertHtml("<p>LOREM IPSUM DOLOR SIT AMET</p>");
}
doc.UpdateFields();
doc.UpdatePageLayout();
doc.Save("C:\\Temp\\output.pdf");
output.pdf (71.7 KB)