Free Support Forum - aspose.com

Inserting Hyperlinks- Setting documents Hyperlink Style

Hi,

I am using the InsertHyperlink function of DocumentBuilder to insert a hyperlink into my Aspose.Word.Document. Everything works perfectly as far as inserting the link Big Smile [:D]. However, I am trying to find a way to color the hyperlink in generated Word document to blue. I tried to use the Aspose.Words.Styles collection to apply the font color to the Hyperlink style, but it didn't seem to work. In fact, I iterated through the styles and it did not even find the Hyperlink StyleIdentifier. Any ideas?

Thanks!

Actually, is there just some way I can color the text I inserted as a hyperlink to blue, without having to mess with the hyperlink style?


Before calling DocumentBuilder.InsertHyperlink, set the formatting you want:

builder.PushFont(); //If you want to pop it later

builder.Font.Color = Color.Blue;

builder.Font.Underline = Underline.Single

builder.Font.UnderlineColor = Color.Blue;

builder.InsertHyperlink(...);

builder.PopFont(); //Restore the font that was during last PushFont.

----

if you wanted to use the Hyperlink style:

builder.Font.StyleIdentifier = StyleIdentifier.Hyperlink

builder.InsertHyperlink(...);

It does not matter that there is no Hyperlink style in the styles collection. It is a built in MS Word style and Aspose.Words will create it for your automatically. Same like MS Word creates you Hyperlink style when you first use it.

There was in fact an example in the API reference http://www.aspose.com/Products/Aspose.Words/Api/Aspose.Words.DocumentBuilder.InsertHyperlink.html