Hello,
I want to solve an issue with a table of contents that is generated with migradoc and then rendered to pdf. In short this is how the table of content is generated:
Code:
Section section = document.LastSection;
// add table of contents and add it
var paragraph = section.AddParagraph(ToCBookmark, "Heading1");
paragraph.AddBookmark(ToCBookmark);
paragraph = section.AddParagraph();
paragraph.Style = "TOC";
Hyperlink hyperlink = paragraph.AddHyperlink(CoverBookmark);
hyperlink.AddText(CoverBookmark + "\t");
hyperlink.AddPageRefField(CoverBookmark);
paragraph = section.AddParagraph();
paragraph.Style = "TOC";
hyperlink = paragraph.AddHyperlink(SummaryBookmark);
hyperlink.AddText(SummaryBookmark + "\t");
hyperlink.AddPageRefField(SummaryBookmark);
paragraph = section.AddParagraph();
paragraph.Style = "TOC";
hyperlink = paragraph.AddHyperlink(ToCBookmark);
hyperlink.AddText(ToCBookmark + "\t");
hyperlink.AddPageRefField(ToCBookmark);
paragraph = section.AddParagraph();
paragraph.Style = "TOC";
hyperlink = paragraph.AddHyperlink(DetailedReportBookmark);
hyperlink.AddText(DetailedReportBookmark + "\t");
hyperlink.AddPageRefField(DetailedReportBookmark);
if (report.Root != null)
ReportTableOfContentsR(report.Root, document, 0);
}
The recurse funtion the bookmark and page number are added:
Code:
// create a empty paragraph and add a hyperlink
var paragraph = section.AddParagraph();
paragraph.Style = "TOC";
paragraph.Format.LeftIndent = Unit.FromCentimeter((level + 1) * ToCIndent);
var hyperlink = paragraph.AddHyperlink(bookmarkStr);
// add text with name of bookmark
hyperlink.AddText(String.Format("{0} [", bookmarkStr));
// add a colored status tag to each element
var text = hyperlink.AddFormattedText(statusStr);
text.Font.Bold = true;
text.Font.Color = statusColor;
// finish the ToC element with a tab to create dots
hyperlink.AddText("]\t");
// add the reference for the bookmark
hyperlink.AddPageRefField(bookmarkStr);
and continue recursing on ReportTableOfContentsR. The issue is that on the last line:
Code:
hyperlink.AddPageRefField(bookmarkStr);
The page number is always the page number of page:
Code:
hyperlink.AddPageRefField(DetailedReportBookmark);
Also the links also point to that page bookmark.
The correct bookmarks are added like this:
Code:
var bookmark = row.Cells[0].AddParagraph(bookmarkStr);
bookmark.Style = "HiddenBookmark";
bookmark.Format.OutlineLevel = outLevel;
bookmark.AddBookmark(bookmarkStr);
On the pdf reader I can see the bookmarks but on the TOC links an page numbers are of DetailedReportBookmark
for hints where the bug is, thanks!