我需要在使用 iTextSharp 生成的 PDF 的页脚处放置一个超链接。
我知道如何使用 PdfPageEventHelper 在页脚中打印一些文本但不放置超链接。
public class PdfHandlerEvents: PdfPageEventHelper
{
private PdfContentByte _cb;
private BaseFont _bf;
public override void OnOpenDocument(PdfWriter writer, Document document)
{
_cb = writer.DirectContent;
}
public override void OnEndPage(PdfWriter writer, Document document)
{
base.OnEndPage(writer, document);
_bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
Rectangle pageSize = document.PageSize;
_cb.SetRGBColorFill(100, 100, 100);
_cb.BeginText();
_cb.SetFontAndSize(_bf, 10);
_cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "More information", pageSize.GetRight(200), pageSize.GetBottom(30), 0);
_cb.EndText();
}
}
如何使文本“更多信息”成为超链接?
编辑:
在下面克里斯的回答之后,我也弄清楚了如何在页脚打印图像,这里是代码:
Image pic = Image.GetInstance(@"C:\someimage.jpg");
pic.SetAbsolutePosition(0, 0);
pic.ScalePercent(25);
PdfTemplate tpl = _cb.CreateTemplate(pic.Width, pic.Height);
tpl.AddImage(pic);
_cb.AddTemplate(tpl, 0, 0);