Inserting hyperlink into sentence
Create a document with a clickable hyperlink embedded within a regular paragraph:
- create a paragraph with text containing an embedded hyperlink (Api, ApiDocument, ApiParagraph/AddText);
- insert a hyperlink with custom anchor text that flows naturally within the sentence (ApiRun/AddHyperlink);
- apply default hyperlink styling with blue color and underline formatting (ApiRun).
- Code
- Result
let doc = Api.GetDocument();
let paragraph = doc.GetElement(0);
// Create a paragraph with embedded hyperlink
paragraph.AddText("You can find more details in the ");
paragraph.AddText("official documentation").GetRange().AddHyperlink("https://api.onlyoffice.com/", "api.onlyoffice.com");
paragraph.AddText(" which covers the API in depth. If you are getting started, it's a good idea to review the usage examples first.");
// Set paragraph alignment to left (default)
paragraph.SetJc("left");