I followed this tutorial to get a bookmark TOC working: Manipulate PDF Document in C#|Aspose.PDF for .NET
The problem I’m encountering is when I go to add text into the Chapter’s paragraph. Something is bleeding out of the Chapter and into the TOC. To make this easier to explain here is a test case I created while evaluating this and a screenshot associated with the problem:
Code
Pdf pdf1 = new Pdf();
pdf1.Title = “Test Document”;
pdf1.IsBookmarked = true;
pdf1.BookmarkLevel = 2;
ListSection TOCSection = new ListSection(pdf1);
TOCSection.ListType = ListType.TableOfContents;
pdf1.Sections.Add(TOCSection);
Heading TOC_Heading = new Heading(pdf1, TOCSection, 1);
Segment Heading_segment = new Segment();
Heading_segment.Content = “Table of Contents”;
TOC_Heading.Segments.Add(Heading_segment);
Heading_segment.TextInfo.FontSize = 20;
TOCSection.Paragraphs.Add(TOC_Heading);
Section Chapter = pdf1.Sections.Add();
Heading Chapter_Heading = new Heading(pdf1, Chapter, 2);
Chapter_Heading.HeadingType = HeadingType.EnglishLower;
Segment Chapter_Segment = new Segment(Chapter_Heading);
Chapter_Heading.Segments.Add(Chapter_Segment);
Chapter_Segment.Content = “TITLE TEST”;
Chapter_Heading.IsInList = true;
Chapter.Paragraphs.Add(Chapter_Heading);
//Test Cases
//String text = “
test
”;
//String text = “
Test Item
”;
String text = “
a
b
c
d
”;
text = listItemFixer(text);
Text textblock = new Text(text);
textblock.IsHtmlTagSupported = true;
Chapter.Paragraphs.Add(textblock);
PDF:
http://imgur.com/yC2yG
HTML:
a
b
c
d
As you can see from the image, the Bookmarks tab on the left side has the “TITLE TEST” listed correctly. Then the HTML that I threw into that Chapter of 4 bullets is shown correctly as a bulleted list on page 2, however they also show up in the Bookmarks tab. If I were to set the textblock.IsHtmlTagSupport = false; there is no problem as it isn’t trying to render the HTML into PDF form.
I am not sure if this is a bug or my misunderstanding of creating bookmarks and a Table of Contents.