如何将电子邮件地址链接到 iTextSharp 锚 class?
How can I linkify an email address with the iTextSharp Anchor class?
我有这个代码:
Font LinkFont = FontFactory.GetFont(FontFactory.COURIER, 9, iTextSharp.text.Font.UNDERLINE, BaseColor.BLUE);
Anchor anchor = new Anchor("Adobe Reader", LinkFont);
anchor.Reference = "http://www.adobe.com";
...这对 link 网站非常有效;但是要调用电子邮件客户端,这:
Anchor anchorEmail = new Anchor("Email the Boss", LinkFont);
anchorEmail.Reference = "mailto://bspringsteen@songwritinggenius.art";
...没有。我是不是遗漏了什么,使用了错误的 class,还是什么?
已更新
这个有效:
Anchor anchorFinPol = new Anchor("finnishCarpenters@helsinki.org", LinkFont);
anchorFinPol.Reference = "mailto://finnishCarpenters@helsinki.org";
...但这不是:
Anchor anchorCCO = new Anchor("Danish Danishes", LinkFont);
anchor.Reference = "mailto://danishes@copenhagen.edu";
URI中的//
用于具有权限的协议,例如http
和ftp
。对于表示电子邮件地址的 URI,您应该忽略它们:
var anchor = new Anchor("Example", LinkFont);
anchor.Reference = "mailto:person@example.com";
此外,有时 PDF 渲染器会自动将看起来像链接的内容自动变成实际链接。当实际文本是电子邮件地址时,您所说的示例可能是这样的。这对消费者来说很方便,但对作者来说也很危险,因为您通常无法保证每个人都会使用哪种渲染器。
我有这个代码:
Font LinkFont = FontFactory.GetFont(FontFactory.COURIER, 9, iTextSharp.text.Font.UNDERLINE, BaseColor.BLUE);
Anchor anchor = new Anchor("Adobe Reader", LinkFont);
anchor.Reference = "http://www.adobe.com";
...这对 link 网站非常有效;但是要调用电子邮件客户端,这:
Anchor anchorEmail = new Anchor("Email the Boss", LinkFont);
anchorEmail.Reference = "mailto://bspringsteen@songwritinggenius.art";
...没有。我是不是遗漏了什么,使用了错误的 class,还是什么?
已更新
这个有效:
Anchor anchorFinPol = new Anchor("finnishCarpenters@helsinki.org", LinkFont);
anchorFinPol.Reference = "mailto://finnishCarpenters@helsinki.org";
...但这不是:
Anchor anchorCCO = new Anchor("Danish Danishes", LinkFont);
anchor.Reference = "mailto://danishes@copenhagen.edu";
URI中的//
用于具有权限的协议,例如http
和ftp
。对于表示电子邮件地址的 URI,您应该忽略它们:
var anchor = new Anchor("Example", LinkFont);
anchor.Reference = "mailto:person@example.com";
此外,有时 PDF 渲染器会自动将看起来像链接的内容自动变成实际链接。当实际文本是电子邮件地址时,您所说的示例可能是这样的。这对消费者来说很方便,但对作者来说也很危险,因为您通常无法保证每个人都会使用哪种渲染器。