7

我能够成功地在 pdf 中添加一个友好名称的链接:

            Anchor anchor = new Anchor("Google", linkFont);
            anchor.Reference = "https://www.google.com";
            doc.Add(anchor);

在此处输入图像描述

但是,我无法让锚点在 PdfPCell 中工作。
这是我到目前为止所尝试的:

            var memberCell = new PdfPCell();
            Anchor anchor = new Anchor("Google", linkFont);
            anchor.Reference = "https://www.google.com";
            memberCell.AddElement(new Anchor(anchor));

显示异常:System.ArgumentException: Element not allowed。

我也试过:

            var memberCell = new PdfPCell();
            Anchor anchor = new Anchor("Google", linkFont);
            anchor.Reference = "https://www.google.com";
            memberCell.AddElement(new Phrase(anchor));

这不会引发异常,但它不是链接,它只是“Google”这个词。

我目前正在使用最新版本的 iTextSharp v.(5.4.4.0)
对此的任何帮助将不胜感激。

4

1 回答 1

17

而不是Anchor使用 aChunk并调用该SetAnchor()方法:

var c = new Chunk("Google");
c.SetAnchor("https://www.google.com");
memberCell.AddElement(c);
于 2013-11-06T21:49:40.067 回答