Я попробовал 3 разных способа отображения номеров страниц, OnCloseDocument
контент не отображается на странице, ни одна из них не работала.
My Intention отображает Номера страниц, как это
1 из 10
2 0f 10
..............
............
10 из 10
на каждой странице
Я знаю, как отображать
1
2
3
4
....
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
}
1ST WAY:
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);
}
2ND WAY:
public override void OnCloseDocument(PdfWriter writer, Document document)
{
ColumnText.ShowTextAligned(template,Element.ALIGN_CENTER,new
Phrase(writer.PageNumber.ToString()), 500, 140, 0);
}
3RD WAY:
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();
}
Я делаю что-то неправильно?