using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iTextSharp.text.pdf;
using iTextSharp.text;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iTextSharp.text.pdf;
using iTextSharp.text;
using System.IO;
{
public class PageNumber
{
public void NumberPage(string Path,int PageNumber)
{
Document doc = new Document();
PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(Path, FileMode.Create));
doc.Open();
PdfContentByte cb = writer.DirectContent;
PdfTemplate template = cb.CreateTemplate(50, 50);
BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
for (int i = 0; i < PageNumber; i++)
{
String PageText = "Page " + writer.PageNumber + " of ";
float len = bf.GetWidthPoint(PageText, 12);
cb.BeginText();
cb.SetFontAndSize(bf, 12);
cb.SetTextMatrix(280, 40);
cb.ShowText(PageText);
cb.EndText();
cb.AddTemplate(template, 280 + len, 40);
doc.NewPage();
}
template.BeginText();
template.SetFontAndSize(bf, 12);
template.ShowText((writer.PageNumber - 1).ToString());
template.EndText();
doc.Close();
}
}
}