Create an Image Hyperlink in Word in C#, VB.NET

With linked images, you can direct users to a URL when they click the image. This article will show you how to create image hyperlinks in a Word document by using Spire.Doc.

Step 1: Create a Word document, add a section and a paragraph.

Document doc = new Document();
Section section = doc.AddSection();
Paragraph paragraph = section.AddParagraph();

Step 2: Load an image to a DocPicture object.

DocPicture picture = new DocPicture(doc);
picture.LoadImage(Image.FromFile("logo.png"));

Step 3: Add an image hyperlink to the paragraph.

paragraph.AppendHyperlink("www.e-iceblue.com", picture, HyperlinkType.WebLink);

Step 4: Save the file.

doc.SaveToFile("output.docx", FileFormat.Docx);

Output:

Create an Image Hyperlink in Word in C#, VB.NET

Full Code:

[C#]
Document doc = new Document();
Section section = doc.AddSection();

Paragraph paragraph = section.AddParagraph();
Image image = Image.FromFile("logo.png");
DocPicture picture = new DocPicture(doc);
picture.LoadImage(image);
paragraph.AppendHyperlink("www.e-iceblue.com", picture, HyperlinkType.WebLink);

doc.SaveToFile("output.docx", FileFormat.Docx);
[VB.NET]
Document doc = New Document()
Dim section As Section = doc.AddSection()

Dim paragraph As Paragraph = section.AddParagraph()
Dim image As Image = Image.FromFile("logo.png")
Dim picture As DocPicture = New DocPicture(doc)
picture.LoadImage(image)
paragraph.AppendHyperlink("www.e-iceblue.com", picture, HyperlinkType.WebLink)
 
doc.SaveToFile("output.docx", FileFormat.Docx)