我正在尝试使用iTextSharp在PDF文档的每个页面上创建一个页脚,其格式为Page#of#,跟随iText页面和书籍上的教程.虽然我一直在cb.SetFontAndSize(helv,12)上得到一个例外; - 未将对象引用设置为对象.有谁能看到这个问题?代码如下.
谢谢,罗布
public class MyPdfPageEventHelpPageNo : iTextSharp.text.pdf.PdfPageEventHelper
{
protected PdfTemplate total;
protected BaseFont helv;
private bool settingFont = false;
public override void OnOpenDocument(PdfWriter writer, Document document)
{
total = writer.DirectContent.CreateTemplate(100, 100);
total.BoundingBox = new Rectangle(-20, -20, 100, 100);
helv = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
}
public override void OnEndPage(PdfWriter writer, Document document)
{
PdfContentByte cb = writer.DirectContent;
cb.SaveState();
string text = "Page " + writer.PageNumber + " of ";
float textBase = document.Bottom - 20;
float textSize = 12; …Run Code Online (Sandbox Code Playgroud)