Free Support Forum - aspose.com

Convert Run to Hyperlink

Is it possible to easily apply a hyperlink to a Run that already exists within a Document?

Hi Alex,


Thanks for your inquiry. Please use the following code snippet to achieve your requirements. The following code example gets the first Run node of second Paragraph in the document and insert hyperlink. Hope this helps you. Please let us know if you have any more queries.

<span style=“font-size:
10.0pt;font-family:“Courier New”;color:#2B91AF;mso-no-proof:yes”>Document<span style=“font-size:10.0pt;font-family:“Courier New”;mso-no-proof:yes”> doc = new Document(MyDir

  • “in.docx”);<o:p></o:p>

DocumentBuilder builder = new DocumentBuilder(doc);

//Get second paragraph of document

Paragraph para = (Paragraph)doc.getChild(NodeType.PARAGRAPH, 1, true);

//Get first Run node

Run run = (Run)para.getChild(NodeType.RUN, 0, true);

builder.moveTo(run);

builder.getFont().setStyleIdentifier(StyleIdentifier.HYPERLINK);

builder.insertHyperlink(run.getText(), "http://www.aspose.com/", false);

run.remove();

doc.save(MyDir + "Out.docx");