I have a project that needs a hyperlink embedded in an image that is part of a header. The Header is replicating to additional PDF pages automatically.
Just to be clear, I want to generate the PDF, and then click on the image and a browser tab will open up and display a website. I do not want to pull an Image from a website and imbed it into my PDF.
The image is the first object in the document.
My PDF is working great otherwise.
Here is some of my code which gets the image and displays it:
bmp.Save(combinesfinalpath); // Save the Image
// Retrieve the Image and add to the Header
MigraDoc.DocumentObjectModel.Shapes.Image image = sec.Headers.Primary.AddImage(@"C:\Users\" + userName + @"\" + "AppData" + @"\" + "Roaming" + @"\" + "PN" + @"\" + "PH2.png");
//Adjust the Image to fit page
image.Height = "3.0cm";
image.Width = "16.0cm";
image.LockAspectRatio = true;
// Start Adding Header Text
sec.Headers.Primary.AddParagraph(); // insert blank paragraph
Paragraph paragraph = sec.Headers.Primary.AddParagraph();
paragraph.Format.Font.Color = Colors.Red;
paragraph.Format.Font.Size = "9";
paragraph.Format.Alignment = ParagraphAlignment.Right;
paragraph.AddFormattedText("Website | Facebook | Instagram ", TextFormat.Bold);
....code continues
Examples for Hypertexting just plain Text is fairly easy, but with a header image it's a little harder to find.
I did find this, but the example does not have the image as part of the header:
Hyperlink hyperlink = paragraph.AddHyperlink(str, hyperlinkType.Web)
hyperlink.AddImage(...);
A further issue is, because the Image is the first object, it is not part of a paragraph, so the paragraph reference errors out (not defined).
That example is also from a forum post dated 2008, so not sure if it's the best solution.
Any help would be appreciated!