I have created a pdf with an image in it using itextsharp library and c#. Now i need to have a hyperlink on that image so that when clicked on it, it goes to a specific site. How do i do it? I was trying to find a property linked to the image object but couldn't.
3
votes
2 Answers
5
votes
You must use an Anchor
Chunk cImage = new Chunk(yourImage, 0, 0, false);
Anchor anchor = new Anchor(cImage);
anchor.Reference = "www.yourAddress.com";
document.Add(anchor);
0
votes
for iText7
var url = "micorosft.com";
var fbImageData = ImageDataFactory.Create("c:/temp/fb.png");
var fbImage = new Image(fbImageData);
var twImageData = ImageDataFactory.Create("c:/temp/tw.png");
var twImage = new Image(twImageData);
fbImage.SetMaxWidth(16);
fbImage.SetMaxHeight(16);
fbImage.SetAction(PdfAction.CreateURI($"https://www.facebook.com/sharer/sharer.php?u={url}"e={"quotegoeshere"}"));
twImage.SetMaxWidth(16);
twImage.SetMaxHeight(16);
twImage.SetAction(PdfAction.CreateURI($"https://twitter.com/intent/tweet?text={"randomtextgoeshere"}" + $" {url}"));