DocumentBuilderInsertHyperlink Method |
Namespace: Aspose.Words
Note that you need to specify font formatting for the hyperlink display text explicitly using the Font property.
This methods internally calls InsertField(String) to insert an MS Word HYPERLINK field into the document.
Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.Write("Please make sure to visit "); // Specify font formatting for the hyperlink builder.Font.Color = Color.Blue; builder.Font.Underline = Underline.Single; // Insert the link. builder.InsertHyperlink("Aspose Website", "http://www.aspose.com", false); // Revert to default formatting builder.Font.ClearFormatting(); builder.Write(" for more information."); doc.Save(ArtifactsDir + "DocumentBuilder.InsertHyperlink.doc");
Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); builder.StartBookmark("Bookmark1"); builder.Write("Bookmarked text."); builder.EndBookmark("Bookmark1"); builder.Writeln("Some other text"); // Specify font formatting for the hyperlink builder.Font.Color = Color.Blue; builder.Font.Underline = Underline.Single; // Insert hyperlink // Switch \o is used to provide hyperlink tip text builder.InsertHyperlink("Hyperlink Text", @"Bookmark1"" \o ""Hyperlink Tip", true); // Clear hyperlink formatting builder.Font.ClearFormatting(); doc.Save(ArtifactsDir + "DocumentBuilder.InsertHyperlinkToLocalBookmark.doc");
Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Set up font formatting and write text that goes before the hyperlink builder.Font.Name = "Arial"; builder.Font.Size = 24; builder.Font.Bold = true; builder.Write("To go to an important location, click "); // Save the font formatting so we use different formatting for hyperlink and restore old formatting later builder.PushFont(); // Set new font formatting for the hyperlink and insert the hyperlink // The "Hyperlink" style is a Microsoft Word built-in style so we don't have to worry to // create it, it will be created automatically if it does not yet exist in the document builder.Font.StyleIdentifier = StyleIdentifier.Hyperlink; builder.InsertHyperlink("here", "http://www.google.com", false); // Restore the formatting that was before the hyperlink. builder.PopFont(); builder.Writeln(". We hope you enjoyed the example."); doc.Save(ArtifactsDir + "DocumentBuilder.PushPopFont.doc");