We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Add bookmark for table and figure and replace text with hyperlink using C#

Hi

I am using Aspose.Word.dll 10.5.0.0 license for generating word document.

In our application there is requirment in which we have to add bookmark in all caption for table and figure and correspoing caption text like figure 1 and figure 2 has to search in a complete document and replace this text as a hyperlink with url of same bookmark value.

So is there any way to search a text in input document and replace it with hyperlink.or is it possible to perform above approach using aspose on attached document.

So,please let us know is there any way to insert hyperlink for this text in word document.

Please provide the code if its possible.

Thanks

Samanvay

Hi Samanvay,

Thanks for your query. In your case, Add bookmark without content in your document at the place of text (Figure 1) and insert hyperlink at bookmark’s position by using following code snippet. Let me know, If you have any further queries.

Document doc = new Document(DirDoc + "InputDoc.docx");

DocumentBuilder builder = new DocumentBuilder(doc);

//move to the bookmark and insert hyperlink

builder.MoveToBookmark("Figure1");

builder.Font.StyleIdentifier = StyleIdentifier.Hyperlink;

builder.InsertHyperlink("Figure 1", "_Toc256000001", true);

//remove the bookmark

doc.Range.Bookmarks["Figure1"].Remove();

doc.Save(DirDoc + "Out.docx");

hi

Thanks for your quick response.
In these case if we searched figure 1 for adding bookmark “figure 1” then it also add bookmark for figure 11 becuase it contain ‘figure 1’ word so. how can we avoid this. we have to only perform operation in figure 1 not figure 11.

so please let us if any solution is possible for it.

Hi Samanvay,

Can you please share, how are you creating document file? Are you creating .doc file by using MS word or by Aspose.Words?

If you are creating doc file by using MS word manually, you insert the bookmark at the position of text (Figure 1, Figure 11) manually. After this use the code mentioned in my previous reply.

If you are creating doc file by code (by using Aspose.Words), then you can insert hyperlink to bookmark at any position. Please see code in my previous reply.