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

Free Support Forum - aspose.com

Formatted Text in Hyperlinks

Hi

I’m using Aspose Words 15.9, Visual Studio 2013, and .NET 4.5.

I would like to be able to use formatted text as the display text of a hyperlink inserted into a document using DocumentBuilder.

For example, the code line:

builder.InsertHyperlink(“Text with bold and italic formatting”, “http://www.aspose.com”, false);

Would insert a link into a document with the “Text with bold and italic formatting” in the standard hyperlink style.

But I want to make the words “bold” and “italic” match their formatting. So the link would look more like:

Text with bold and italic formatting

Is there a way I can do this with DocumentBuilder (or without it, whatever works)?

I tried moving to the field.Separator, and then outputting text using the standard DocumentBuilder.Write() method, but that didn’t work:

Field field = builder.InsertHyperlink(string.Empty, url, false);
builder.MoveTo(field.Separator);
builder.Write(“Link Text”);

Any suggestions?

Thanks
Chris.

Never mind, I’ve figured it out. It came to me five minutes after I’d posted the original request.


In case anyone wants to do this, I was really close in my attempt. Instead of moving to the field.Separator, I should have moved to the field.End:

Field field = builder.InsertHyperlink(string.Empty, url, false);
builder.MoveTo(field.End);
builder.Write(“Text with “);
builder.Bold = true;
builder.Write(“bold”);
builder.Bold = false;
builder.Write(” and “);
builder.Italic = true;
builder.Write(“italic”);
builder.Italic = false;
builder.Write(” formatting”);
builder.MoveToDocumentEnd();

Thanks
Chris

Hi Chris,

Thanks for your inquiry. It is nice to hear from you that you have found the solution of your query. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.