PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Jun 30, 2024 2:12 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Mon Jun 15, 2015 2:17 pm 
Offline

Joined: Mon Jun 15, 2015 2:10 pm
Posts: 1
I am working on a project where I need to create a PDF file and a RTF file, having a Table Of Content. I am doing this using MigraDoc.

The code for Table of content for both the files is :

public static void DefineTableOfContents(Document document)
{
Section section = document.LastSection;

section.AddPageBreak();
Paragraph paragraph = section.AddParagraph("Table of Contents");
paragraph.Format.Font.Size = 14;
paragraph.Format.Font.Bold = true;
paragraph.Format.SpaceAfter = 24;
paragraph.Format.OutlineLevel = OutlineLevel.Level1;

paragraph = section.AddParagraph();
paragraph.Style = "TOC";
Hyperlink hyperlink = paragraph.AddHyperlink("ParaBookmark");
hyperlink.AddText("Paragraphs\t");
hyperlink.AddPageRefField("ParaBookmark");

paragraph = section.AddParagraph();
paragraph.Style = "TOC";
hyperlink = paragraph.AddHyperlink("AJBookmark");
hyperlink.AddText("AJ\t");
hyperlink.AddPageRefField("AJBookmark");

paragraph = section.AddParagraph();
paragraph.Style = "TOC";
hyperlink = paragraph.AddHyperlink("TablesBookmark");
hyperlink.AddText("Tables\t");
hyperlink.AddPageRefField("TablesBookmark");

paragraph = section.AddParagraph();
paragraph.Style = "TOC";
hyperlink = paragraph.AddHyperlink("ChartsBookmark");
hyperlink.AddText("Charts\t");
hyperlink.AddPageRefField("ChartsBookmark");
}

For Pdf, the code is working fine with all the page numbers appearing properly, but for the RTF file, we get an output like :

Table of Contents
Paragraphs.................................................... < Please update this field. >
AJ................................................................ < Please update this field. >
Tables.......................................................... < Please update this field. >
Charts.......................................................... < Please update this field. >

After googling I came to understand that for the RTF's page numbers to appear on the TOC, we would have to update the whole document manually in MS Word, by using ctrl+A and then F9.

Is there any programmatic way so that I could get the correct table of content with page numbers for RTF, so that we don't need to update the document manually?


Top
 Profile  
Reply with quote  
PostPosted: Mon Jun 15, 2015 2:24 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3100
Location: Cologne, Germany
Hi!
aamir wrote:
Is there any programmatic way so that I could get the correct table of content with page numbers for RTF, so that we don't need to update the document manually?
Probably there are several ways, like VBA for Word or a Word Add-In that does it. MigraDoc cannot fill those fields.

Also discussed here:
http://stackoverflow.com/a/30847786/162529

_________________
Regards
Thomas Hoevel
PDFsharp Team


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

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 35 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