我尝试了3种显示页码的方法,页面 OnCloseDocument中未显示内容,但没有一种有效。我的目的是显示页码这样的10 12 10 0F..........................在每一页上的10 10我知道怎么显示1234....10但不知道如何显示总页数我正在使用 OnCloseDocument 显示页数,但其中的内容未显示。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) { template= writer.DirectContent.CreateTemplate(100, 100); bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); } public override void OnCloseDocument(PdfWriter writer, Document document) { //See below }第一种方式: public override void OnCloseDocument(PdfWriter writer, Document document) { //I create a table with one column like below. PdfPTable pageNumber2 = new PdfPTable(1); pageNumber2.TotalWidth = 50; pageNumber2.HorizontalAlignment = Element.ALIGN_RIGHT; pageNumber2.AddCell(BuildTable2RightCells("Page " + writer.PageNumber)); pageNumber.AddCell(BuildTable2LeftCells(writer.PageCount)); pageNumber2.WriteSelectedRows(0, -1, 500, (document.PageSize.GetBottom(140)), cb); } 第二路: public override void OnCloseDocument(PdfWriter writer, Document document) { ColumnText.ShowTextAligned(template,Element.ALIGN_CENTER,new Phrase(writer.PageNumber.ToString()), 500, 140, 0); }第三种方式: public override void OnCloseDocument(PdfWriter writer, Document document) { template.BeginText(); template.SetFontAndSize(bf, 8); template.SetTextMatrix(500, 140); template.ShowText(Convert.ToString((writer.PageNumber - 1))); template.EndText(); }我做错什么了吗?
2 回答
- 2 回答
- 0 关注
- 369 浏览
添加回答
举报
0/150
提交
取消