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);
MigraDoc.DocumentObjectModel.Shapes.Image image = sec.Headers.Primary.AddImage(@"C:\Users\" + userName + @"\" + "AppData" + @"\" + "Roaming" + @"\" + "PN" + @"\" + "PH2.png");
image.Height = "3.0cm";
image.Width = "16.0cm";
image.LockAspectRatio = true;
sec.Headers.Primary.AddParagraph();
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
What I have tried:
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(...);
I don't define my first paragraph until after the Image is displayed, so I get an error on the line. Again this image is in the Header, so I'm searching for an example or help on that.
So to be more specific, the error I get is "Cannot use local variable before it's declared".
For the heck of it I typed in this line of code right after the MigraDoc Image, but before I add the first paragraph (text):
Hyperlink hyperlink = paragraph.AddHyperlink("http://yahoo.com/", HyperlinkType.Web);
With the line right above, it didn't like paragraph because it has not yet been declared, which makes sense.
This leads me to the believe it might not be the right solution for me, not only because it does not reference the Header status, but because the image is declared before I need a paragraph to start displaying text.
I can always add a new paragraph in, but not sure how to add the image, as a header, to the PDF, which is my original problem.
Sorry for the run on...