Working with Hyperlinks

A hyperlink is a text or an image user can click on, and jump to another document/URL. Aspose.Note APIs allows adding a hyperlink in the OneNote Document. The code example given below demonstrates how to add a hyperlink to the OneNote document.

 1// The path to the documents directory.
 2string dataDir = RunExamples.GetDataDir_Tasks();
 3
 4// Create an object of the Document class
 5Document doc = new Document();
 6// Initialize Page class object
 7Aspose.Note.Page page = new Aspose.Note.Page(doc);
 8// Initialize Title class object
 9Title title = new Title(doc);
10
11ParagraphStyle defaultTextStyle = new ParagraphStyle
12{
13    FontName = "Arial",
14    FontSize = 10,
15    FontColor = SystemColors.WindowText
16};
17RichText titleText = new RichText(doc)
18{
19    Text = "Title!",
20    ParagraphStyle = defaultTextStyle
21};
22Outline outline = new Outline(doc)
23{
24    MaxWidth = 200,
25    MaxHeight = 200,
26    VerticalOffset = 100,
27    HorizontalOffset = 100
28};
29OutlineElement outlineElem = new OutlineElement(doc);
30TextStyle textStyleRed = new TextStyle
31{
32    FontColor = Color.Red,
33    FontName = "Arial",
34    FontSize = 10,
35    RunIndex = 8//this style will be applied to 0-7 characters.
36};
37TextStyle textStyleHyperlink = new TextStyle
38{
39    RunIndex = 17,//this style will be applied to 8-16 characters.
40    IsHyperlink = true,
41    HyperlinkAddress = "www.google.com"
42};
43RichText text = new RichText(doc)
44{
45    Text = "This is hyperlink. This text is not a hyperlink.",
46    ParagraphStyle = defaultTextStyle,
47    Styles = { textStyleRed, textStyleHyperlink }
48};
49
50title.TitleText = titleText;
51page.Title = title;
52outlineElem.AppendChildLast(text);
53// Add outline elements
54outline.AppendChildLast(outlineElem);
55// Add Outline node
56page.AppendChildLast(outline);
57// Add Page node
58doc.AppendChildLast(page);
59
60dataDir = dataDir + "AddHyperlink_out.one";
61// Save OneNote document
62doc.Save(dataDir);
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.