View previous topic :: View next topic |
Author |
Message |
woany
Joined: 10 Dec 2008 Posts: 2
|
Posted: Wed Dec 10, 2008 3:43 pm Post subject: Table of Contents |
|
|
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 |
|
Back to top |
|
|
Thomas Hoevel
Joined: 16 Oct 2006 Posts: 387 Location: Cologne, Germany
|
Posted: Thu Dec 11, 2008 9:03 am Post subject: |
|
|
The bookmark tree is created from the paragraphs with outline level.
They are all on the TOC page in your sample ...
Set the outline level where you add the bookmarks!
BTW: bookmarks are only strings. You can add references to the TOC before adding the bookmarks to the document.
The predefined styles Heading1, Heading2, ... have the appropriate outline level. You don't have to set the outline level of a paragraph if you set the style of the paragraph. _________________ Regards
Thomas Hoevel
PDFsharp Team |
|
Back to top |
|
|
woany
Joined: 10 Dec 2008 Posts: 2
|
Posted: Thu Dec 11, 2008 12:45 pm Post subject: Ah |
|
|
Ah, so thats how it works! Thanks for the quick response. Excellent library by the way. |
|
Back to top |
|
|
|