Hi
How can i add a Header in Table of Contents?
Regards
Markus
This message was posted using Page2Forum from Manipulating List of Contents - Aspose.Pdf for .NET and Java
Hi
How can i add a Header in Table of Contents?
Regards
Markus
Hello Markus,
Thanks for considering Aspose.
Let me share some details regarding the DOC (Document Object Model) of Aspose.Pdf. A PDF generated by Aspose.Pdf is comprised of one or more Sections, where a section contains one or more paragraphs. A paragraph can be an Image, Graph, Text, Floating Box, Table, Attachment, Heading or a Form Field.
To accomplish your requirement, you can create TOC section, create Header Section object and add the Header object to TOC section. Please try using the following code snippet in whic I’ve created TOC section containing Header object and another section containing Text paragraph. The resultant PDF is also in attachment, please take a look.
<C#>
Pdf pdf = new Pdf();
//Create a list section
ListSection tocSection = new ListSection("Table Of Contents");
//Set its list type as table of of content
tocSection.ListType = ListType.TableOfContents;
//Add the list section to the sections collection of the Pdf document
pdf.Sections.Add(tocSection);
//Instantiate HeaderFooter object and pass the Section reference in which
//the header or footer is to be added
Aspose.Pdf.HeaderFooter hf1 = new Aspose.Pdf.HeaderFooter(tocSection);
//Set the header of odd pages of the PDF document
tocSection.OddHeader = hf1
//Set the header of even pages of the PDF document
tocSection.EvenHeader = hf1;
//Instantiate a Text paragraph that will store the content to show as header
Text text = new Text(hf1, "header in TOC");
//Add the text object to the Paragraphs collection of HeaderFooter object to
//display header on the pages of PDF document
hf1.Paragraphs.Add(text);
// add a new section to PDF file and add a Text paragraph
Aspose.Pdf.Section sec1 = pdf.Sections.Add();
sec1.Paragraphs.Add(new Text("This text is neither in Header section nor in TOC"));
pdf.Save(@"d:/pdftest/Header_TOC_test.pdf");
In order to have a better understanding of Document Structure generated by Aspose.Pdf, please visit the Aspose.Pdf Document Object Model (DOM).
In case of any further query, please feel free to contact.