0
我需要把一個超鏈接在使用iTextSharp的生成我的PDF頁腳。超鏈接使用iTextSharp的
我知道如何使用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);
真棒克里斯,它的工作原理,我從這個代碼做了很多新的技巧!謝謝! – 2013-04-11 23:15:04