This project has moved and is read-only. For the latest updates, please go here.

Document headings and internal anchor tags

Mar 25, 2014 at 5:46 PM
Hi all,

I'm trying to recreate a legacy document that has a pseudo table-of-contents at the top. Each entry in this table of contents then links to a header further down the document. I cannot for the life of me figure out how to make a given piece of text an anchor eg: 'Heading 1' and then link to it from the top of the document.

Can anybody help me?

Mar 26, 2014 at 11:34 AM
Edited Mar 26, 2014 at 11:34 AM
I've managed to solve the Heading bit, and I've made this into an extension method
public static class ExtensionMethods
public static Paragraph Heading1(this Paragraph paragraph)
    paragraph.StyleName = "Heading1";
    return paragraph;
Paragraph pTitle = document.InsertParagraph();
all I need now is to be able to hyperlink to these headings from another location in the document - anybody have any ideas on how to do this?
Mar 26, 2014 at 1:15 PM
Some further progress made, though I now believe I'm at a dead end.

I've realised that I need to add a bookmark to the destination I need to link to. Bookmark support is not in the latest nuget package, but I've made a copy of the source and compiled it locally to make it available.

The final hurdle is adding the link to the bookmark. The hyperlink code will not support this as it needs a fully formed URI as a parameter. Does anybody have any idea how to do this?
Mar 28, 2014 at 11:57 AM
Edited Mar 28, 2014 at 11:57 AM
I've just expanded on my Heading code to provide an enum supporting Heading1 - Heading9.

I've submitted this as patch 16118
Mar 30, 2014 at 12:16 PM
Thanks. I've tested and applied the patch.
Apr 10, 2014 at 1:53 PM
@MadBoy - any chance of a new official build/nuget package so I can use official nuget package with these additions?

Apr 12, 2014 at 9:09 PM
I guess I could try to make official release sometime soon. Not sure if it's stable enough.