Tags

, , ,

Create a class that inherit by PdfPageEventHelper .
and override OnEndPage Method. please check follwoing code.

public partial class Footer : PdfPageEventHelper

{

public override void OnEndPage(PdfWriter writer, Document doc)

{

var content = writer.DirectContent;
var pageBorder = new Rectangle(doc.PageSize);

pageBorder.Left += doc.LeftMargin;
pageBorder.Right -= doc.RightMargin;
pageBorder.Top -= doc.TopMargin;
pageBorder.Bottom += doc.BottomMargin;

content.SetColorStroke(BaseColor.BLACK);
content.Rectangle(pageBorder.Left, pageBorder.Bottom, pageBorder.Width, pageBorder.Height);
content.Stroke();
}

}

after this

iTextSharp.text.Document doc = new iTextSharp.text.Document(PageSize.A4);

string path = Server.MapPath(“PDF”);
PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(path + “\\hello.pdf”, FileMode.Create));

doc.Open();

writer.PageEvent = new Footer();

doc.Add(new Paragraph(“Hello World!”));

doc.Add(new Paragraph(“Hello World on a new page!”));

doc.Close();

Hello.pdf

plesae use and update me.

Rs. 163 .Coms at GoDaddy!

Advertisements