【问题标题】:iTextSharp Use Link Inside PdfPCelliTextSharp 在 PdfPCell 中使用链接
【发布时间】:2013-11-18 07:58:54
【问题描述】:

我能够成功地在 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)
对此的任何帮助将不胜感激。

【问题讨论】:

    标签: pdf hyperlink anchor itextsharp cell


    【解决方案1】:

    使用Chunk 代替Anchor 并调用SetAnchor() 方法:

    var c = new Chunk("Google");
    c.SetAnchor("https://www.google.com");
    memberCell.AddElement(c);
    

    【讨论】:

      猜你喜欢
      • 2016-03-28
      • 2010-12-02
      • 2014-09-21
      • 2011-02-10
      • 2011-03-02
      • 1970-01-01
      • 2016-01-12
      • 2012-11-14
      • 2014-03-04
      相关资源
      最近更新 更多