Free Support Forum -

Linking an Image to Bookmark

Using DocumentBuilder.InsertHyperLink() Iam not able to link the image to bookmark. How can I link an Image to an existing bookmark?

Unfortunately in the current version we don't have simple method to do that. But it is technically possible to do through node manipulation.

Here is an example of how that could be done when building document dynamically:

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);




builder.Writeln("Some text");

// Specify font formatting for the hyperlink.

builder.Font.Color = System.Drawing.Color.Blue;

builder.Font.Underline = Underline.Single;

// Insert the hyperlink.

builder.InsertHyperlink("Link text", "Hello", true);

// Clear hyperlink formatting.


builder.Writeln("Some text");

builder.InsertHyperlink("Link text", "Hello", true);

string imageFileName = Application.StartupPath + @"\test.gif";


InlineShape shape = (InlineShape)builder.CurrentParagraph.LastChild;


builder.CurrentParagraph.InsertBefore(shape, builder.CurrentParagraph.LastChild);


When i used the above code it was linking the image to Bookmark but the Display text (link text in the above example) is getting deleted.

This can be worked around with the following trick:

builder.InsertHyperlink("This text does not matter", @"Hello "" \o ""This text will be displayed as a link"" ", true);