I am trying to get a table of contents working, I've looked at the example in the HelloMigraDoc example.
The bookmark tree is generated correctly but when you click on the bookmark entry (in the treeview), the document does not go to the page clicked.
My simple example code is below:
Code:
Document document = new Document();
Section sectionToc = document.AddSection();
Section section = document.AddSection();
Paragraph paragraph = section.AddParagraph("PARA1");
paragraph.AddBookmark("SECTION1");
section = document.AddSection();
paragraph = section.AddParagraph("PARA2");
paragraph.AddBookmark("SECTION2");
paragraph = sectionToc.AddParagraph();
paragraph.Format.OutlineLevel = OutlineLevel.Level1;
Hyperlink hyperlink = paragraph.AddHyperlink("SECTION1");
hyperlink.AddText("SECTION1\t");
hyperlink.AddPageRefField("SECTION1");
paragraph = sectionToc.AddParagraph();
paragraph.Format.OutlineLevel = OutlineLevel.Level2;
hyperlink = paragraph.AddHyperlink("SECTION2");
hyperlink.AddText("SECTION2\t");
hyperlink.AddPageRefField("SECTION2");
PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true);
pdfRenderer.Document = document;
pdfRenderer.RenderDocument();
pdfRenderer.Save("test.pdf");
Process.Start("test.pdf");
Can anyone see what i am doing wrong?
Many thanks