如何使用MigraDoc和C#向标题图像添加超链接?
我有一个项目,需要一个超链接嵌入在一个图像,是标题的一部分。标题将自动复制到其他PDF页面 为了清楚起见,我想生成PDF,然后单击图像,浏览器选项卡将打开并显示一个网站。 我不想从网站中提取图像并将其嵌入到我的PDF中 图像是文档中的第一个对象 我的PDF在其他方面工作得很好 下面是我的一些代码,用于获取图像并显示它:如何使用MigraDoc和C#向标题图像添加超链接?,c#,pdf,migradoc,C#,Pdf,Migradoc,我有一个项目,需要一个超链接嵌入在一个图像,是标题的一部分。标题将自动复制到其他PDF页面 为了清楚起见,我想生成PDF,然后单击图像,浏览器选项卡将打开并显示一个网站。 我不想从网站中提取图像并将其嵌入到我的PDF中 图像是文档中的第一个对象 我的PDF在其他方面工作得很好 下面是我的一些代码,用于获取图像并显示它: bmp.Save(combinesfinalpath); // Save the Image // Retrieve the Image and add to the H
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
纯文本超文本的例子是相当容易的,但对于标题图像,要找到它就有点困难了
我确实发现了这一点,但该示例没有将图像作为标题的一部分:
Hyperlink hyperlink = paragraph.AddHyperlink(str, hyperlinkType.Web)
hyperlink.AddImage(...);
另一个问题是,由于图像是第一个对象,它不是段落的一部分,因此段落引用出错(未定义)
这个例子也来自2008年后的一个论坛,所以不确定这是否是最好的解决方案
任何帮助都将不胜感激 现在已修复此问题!增加第二段