我嘗試了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 回答
- 0 關注
- 397 瀏覽
添加回答
舉報
0/150
提交
取消