Hi
I am using Aspose Words 15.9, Visual Studio 2013, and .NET 4.5.
I am using DocumentBuilder to create a document, and part of the requirement is to include hyperlinks to web sites. This is pretty easy to achieve, using the DocumentBuilder function InsertHyperlink.
The trouble is, styling the links. Simply using InsertHyperlink adds the link OK, but it appears no different from the surrounding text. I have been trying to apply the inbuilt “Hyperlink” style to the text using the following code:
builder.Font.StyleName="Hyperlink";
builder.InsertHyperlink("Display Text", "[link]", false);
That didn’t work. Neither did using:
builder.Font.Style.Name = "Hyperlink";
for the first line. I even tried locating the Hyperlink style using the Document.Styles collection, and setting the style that way. I could find the style, but applying it had no effect.
The problem appears to be that the style is applied to the text, but it doesn’t affect the appearance - even though it should. If you open the generated document in MS Word and move the cursor to the hyperlink, the selected style appears as “Hyperlink”, even though the text appears the same as surrounding text. If I “re-apply” the style within MS Word, it suddenly appears correctly.
In the end, the only workaround I could find was to locate the style, and then apply the appropriate settings (bold, italic, underline, color) manually:
builder.Font.Bold = style.Font.Bold;
builder.Font.Italic = style.Font.Italic;
builder.Font.Underline = style.Font.Underline;
builder.Font.Color = style.Font.Color;
While this gets the job done, it is not ideal. Could you tell me what I’m doing wrong with the application of the style to the link?
Thanks
Chris.