We are creating a PDF document from scratch. The headings we are using always have the property “IsKeptWithNext” set, so that they are not written on the bottom of a page without consecutive paragraph.
All headings are listed in a TOC.
If a heading would fit on the bottom of a page, but Aspose must move it to the next page, because the “IsKeptWithNext” condition would be broken, the heading is listed twice in the TOC.
Please see the following code sequence to reproduce the problem.
Thanks for your assistance!
Aspose.Pdf.License license = new Aspose.Pdf.License();
// Instantiate license file
license.SetLicense("LGSolutions.Finance.Portal.Aspose.Pdf.lic");
// Set the value to indicate that license will be embedded in the application
license.Embedded = true;
var pdf = new Aspose.Pdf.Document();
Page TocSection = pdf.Pages.Add();
TocInfo tocInfo = new TocInfo();
TocSection.TocInfo = tocInfo;
tocInfo.FormatArrayLength = 1;
tocInfo.FormatArray[0].TextState.Font = Aspose.Pdf.Text.FontRepository.FindFont("Verdana");
tocInfo.FormatArray[0].TextState.FontSize = 20;
Page page = pdf.Pages.Add();
Aspose.Pdf.Text.TextFragment entry1 = new Aspose.Pdf.Text.TextFragment(@"Entry 1
dfsgdfsgdfs
gdfsg
dfsg
gadag
dsagsdag
dfsagdafsgadfghad dfg
df
gdfs
g
dfg
dfsgdfsgdfsgdsfgdfsg
");
Aspose.Pdf.Text.TextFragment entry2 = new Aspose.Pdf.Text.TextFragment(@"Entry 2
dfsgdfsgdfs
gdfsg
dfsg
dfgdfg
df
gdfs
g
dfg
dfsgdfsgdfsgdsfgdfsg
");
Aspose.Pdf.Text.TextFragment entry3 = new Aspose.Pdf.Text.TextFragment("Entry 3");
Aspose.Pdf.Text.TextFragment entry4 = new Aspose.Pdf.Text.TextFragment("Entry 4");
Aspose.Pdf.Text.TextFragment entry5 = new Aspose.Pdf.Text.TextFragment("Entry 5");
var heading = new Heading(1) { Text = "Header 1" };
heading.IsInList = true;
heading.IsKeptWithNext = true;
heading.TocPage = TocSection;
page.Paragraphs.Add(heading);
page.Paragraphs.Add(entry1);
page.Paragraphs.Add(entry2);
page.Paragraphs.Add(entry3);
var text = new Aspose.Pdf.Text.TextFragment(@"Some text dsfgdfg
dfsgdfsgdfs
gdfsg
dfsg
dvdsagsadgdsg
sdag
sdg
sadg
sad
gasdgadsfgdfagdfa
gdaf
gadf
gadfgdf
g
df
ag
df
gadfg
df
gadfgadfg
adf
g
adfg
dfag
adf
g
adf
g
dfgdfg
sadfdsf
sdafsdaf
dfgdfg
dfg
dsfgdfsgdfsgdfs
gdfgdfsgdfg
gdfsgdf
");
page.Paragraphs.Add(text);
heading = new Heading(1) { Text = "Header 2" };
heading.IsInList = true;
heading.IsKeptWithNext = true;
heading.TocPage = TocSection;
page.Paragraphs.Add(heading);
page.Paragraphs.Add(entry4);
page.Paragraphs.Add(entry5);
try
{
var memoryStream = new MemoryStream();
pdf.Save(memoryStream);
memoryStream.CopyTo(this.Response.OutputStream);
}
catch (Exception ex)
{
}
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition", "inline; filename=Test");
return new EmptyResult();