1

In the DocX library available at : https://github.com/WordDocX/DocX

It is possible to add some hyperlink but i haven't found a way to add internal link.

Does anyone know how to add a link to specific paragraph or to a bookmark ?

G.Dealmeida
  • 325
  • 3
  • 14
  • have you tried just linking to #bookmarkwhatever? – BugFinder Oct 03 '17 at 12:02
  • How ? Any code sample ? – G.Dealmeida Oct 03 '17 at 12:14
  • link to #bookmarkwhatever - same way you link to any other link – BugFinder Oct 03 '17 at 12:28
  • I know how an internal link is constructed, i want to know if there is a way to do it with the DocX library, and how ? How means, i want to see a real example and what function/method/property you are using. To add an hyperlink you type that : Hyperlink h = myDocxDocument.AddHyperlink("Link", "http://www.google.com"); synthesisDocument.Paragraphs[0].InsertHyperlink(h); and obviously if you type that : Hyperlink h = synthesisDocument.AddHyperlink("Link", "#MY_BOOKMARK");synthesisDocument.Paragraphs[0].InsertHyperlink(h); it doesnt work. – G.Dealmeida Oct 03 '17 at 12:58
  • Ok i think you are trolling... of course i did some research !! On google AND StackOverflow – G.Dealmeida Oct 03 '17 at 13:27
  • So you do not understand what i am asking for... stop flooded if you don't intend to help – G.Dealmeida Oct 03 '17 at 13:33
  • I did actually but you keep telling yourself that - considering the fact I was the only one trying to help you. you shot yourself in the foot – BugFinder Oct 03 '17 at 13:35
  • Thank you for trying to help, but when i ask for a code sample and you answer this "link to #bookmarkwhatever - same way you link to any other link" it's quite insulting.... and totally wrong as the code sample i sent demonstrate. If you don't know the answer... fine... admit it and stop the useless flood pls. Thanks – G.Dealmeida Oct 03 '17 at 13:56

2 Answers2

1

The way I've found is:

synthesisDocument.AddHyperlink("Link",new Uri("file:///path/to/doc/file.doc#MY_BOOKMARK")); synthesisDocument.Paragraphs[0].InsertHyperl‌​ink(h)

That way resolve your problem, but only in doc format, when you export to PDF it doesn't work. I hope it helps

REDMAN
  • 91
  • 9
0

As mentioned #BookMark does work if the Uri is created with the UriKind.Relative flag:

 var uri = new Uri("#" + BookMark,UriKind.Relative);
 var hyperLink =  doc.AddHyperlink(textToDisplay, uri  );

Now to use the hyperlink on a paragraph, p:

 p.InsertHyperlink(hyperLink,indexToInsertAt);

I achieved exactly the result I wanted using this in both .docx and .pdf

Hope it works for you,

Nick