PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Apr 28, 2024 12:05 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Table of Contents
PostPosted: Wed Dec 10, 2008 3:43 pm 
Offline

Joined: Wed Dec 10, 2008 3:39 pm
Posts: 2
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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Dec 11, 2008 9:03 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
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


Top
 Profile  
Reply with quote  
 Post subject: Ah
PostPosted: Thu Dec 11, 2008 12:45 pm 
Offline

Joined: Wed Dec 10, 2008 3:39 pm
Posts: 2
Ah, so thats how it works! Thanks for the quick response. Excellent library by the way.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 343 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group