Please check out the sample code below:
  1. private void CreatePDF()  
  2. {  
  3.     string fileName = string.Empty;      
  4.     DateTime fileCreationDatetime = DateTime.Now;      
  5.     fileName = string.Format("{0}.pdf", fileCreationDatetime.ToString(@"yyyyMMdd") + "_" + fileCreationDatetime.ToString(@"HHmmss"));      
  6.     string pdfPath = Server.MapPath(@"~\PDFs\") +   fileName;  
  7.   
  8.     using (FileStream msReport = new FileStream(pdfPath, FileMode.Create))  
  9.     {  
  10.         //step 1  
  11.         using (Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 140f, 10f))  
  12.         {  
  13.             try  
  14.             {  
  15.                 // step 2  
  16.                 PdfWriter pdfWriter = PdfWriter.GetInstance(pdfDoc, msReport);  
  17.                 pdfWriter.PageEvent = new Common.ITextEvents();  
  18.   
  19.                 //open the stream   
  20.                 pdfDoc.Open();  
  21.   
  22.                 for (int i = 0; i < 10; i++)  
  23.                 {  
  24.                     Paragraph para = new Paragraph("Hello world. Checking Header Footer", new Font(Font.FontFamily.HELVETICA, 22));      
  25.                     para.Alignment = Element.ALIGN_CENTER;      
  26.                     pdfDoc.Add(para);      
  27.                     pdfDoc.NewPage();  
  28.                 }  
  29.   
  30.                 pdfDoc.Close();      
  31.             }  
  32.             catch (Exception ex)  
  33.             {  
  34.                 //handle exception  
  35.             }      
  36.             finally  
  37.             {   
  38.             }      
  39.         }      
  40.     }  
  41. }  
And create one class file named ITextEvents.cs and add following code:
  1. public class ITextEvents : PdfPageEventHelper  
  2. {      
  3.     // This is the contentbyte object of the writer  
  4.     PdfContentByte cb;  
  5.   
  6.     // we will put the final number of pages in a template  
  7.     PdfTemplate headerTemplate, footerTemplate;  
  8.   
  9.     // this is the BaseFont we are going to use for the header / footer  
  10.     BaseFont bf = null;  
  11.   
  12.     // This keeps track of the creation time  
  13.     DateTime PrintTime = DateTime.Now;      
  14.  
  15.     #region Fields  
  16.     private string _header;  
  17.     #endregion  
  18.  
  19.     #region Properties  
  20.     public string Header  
  21.     {  
  22.         get { return _header; }  
  23.         set { _header = value; }  
  24.     }  
  25.     #endregion      
  26.   
  27.     public override void OnOpenDocument(PdfWriter writer, Document document)  
  28.     {  
  29.         try  
  30.         {  
  31.             PrintTime = DateTime.Now;  
  32.             bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);  
  33.             cb = writer.DirectContent;  
  34.             headerTemplate = cb.CreateTemplate(100, 100);  
  35.             footerTemplate = cb.CreateTemplate(50, 50);  
  36.         }  
  37.         catch (DocumentException de)  
  38.         {      
  39.         }  
  40.         catch (System.IO.IOException ioe)  
  41.         {      
  42.         }  
  43.     }  
  44.   
  45.     public override void OnEndPage(iTextSharp.text.pdf.PdfWriter writer, iTextSharp.text.Document document)  
  46.     {  
  47.         base.OnEndPage(writer, document);      
  48.         iTextSharp.text.Font baseFontNormal = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 12f, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLACK);      
  49.         iTextSharp.text.Font baseFontBig = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 12f, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLACK);      
  50.         Phrase p1Header = new Phrase("Sample Header Here", baseFontNormal);  
  51.   
  52.         //Create PdfTable object  
  53.         PdfPTable pdfTab = new PdfPTable(3);  
  54.   
  55.         //We will have to create separate cells to include image logo and 2 separate strings  
  56.         //Row 1  
  57.         PdfPCell pdfCell1 = new PdfPCell();  
  58.         PdfPCell pdfCell2 = new PdfPCell(p1Header);  
  59.         PdfPCell pdfCell3 = new PdfPCell();  
  60.         String text = "Page " + writer.PageNumber + " of ";      
  61.   
  62.         //Add paging to header  
  63.         {  
  64.             cb.BeginText();  
  65.             cb.SetFontAndSize(bf, 12);  
  66.             cb.SetTextMatrix(document.PageSize.GetRight(200), document.PageSize.GetTop(45));  
  67.             cb.ShowText(text);  
  68.             cb.EndText();  
  69.             float len = bf.GetWidthPoint(text, 12);  
  70.             //Adds "12" in Page 1 of 12  
  71.             cb.AddTemplate(headerTemplate, document.PageSize.GetRight(200) + len, document.PageSize.GetTop(45));  
  72.         }  
  73.         //Add paging to footer  
  74.         {  
  75.             cb.BeginText();  
  76.             cb.SetFontAndSize(bf, 12);  
  77.             cb.SetTextMatrix(document.PageSize.GetRight(180), document.PageSize.GetBottom(30));  
  78.             cb.ShowText(text);  
  79.             cb.EndText();  
  80.             float len = bf.GetWidthPoint(text, 12);  
  81.             cb.AddTemplate(footerTemplate, document.PageSize.GetRight(180) + len, document.PageSize.GetBottom(30));  
  82.         }  
  83.   
  84.         //Row 2  
  85.         PdfPCell pdfCell4 = new PdfPCell(new Phrase("Sub Header Description", baseFontNormal));  
  86.   
  87.         //Row 3   
  88.         PdfPCell pdfCell5 = new PdfPCell(new Phrase("Date:" + PrintTime.ToShortDateString(), baseFontBig));  
  89.         PdfPCell pdfCell6 = new PdfPCell();  
  90.         PdfPCell pdfCell7 = new PdfPCell(new Phrase("TIME:" + string.Format("{0:t}", DateTime.Now), baseFontBig));      
  91.   
  92.         //set the alignment of all three cells and set border to 0  
  93.         pdfCell1.HorizontalAlignment = Element.ALIGN_CENTER;  
  94.         pdfCell2.HorizontalAlignment = Element.ALIGN_CENTER;  
  95.         pdfCell3.HorizontalAlignment = Element.ALIGN_CENTER;  
  96.         pdfCell4.HorizontalAlignment = Element.ALIGN_CENTER;  
  97.         pdfCell5.HorizontalAlignment = Element.ALIGN_CENTER;  
  98.         pdfCell6.HorizontalAlignment = Element.ALIGN_CENTER;  
  99.         pdfCell7.HorizontalAlignment = Element.ALIGN_CENTER;      
  100.   
  101.         pdfCell2.VerticalAlignment = Element.ALIGN_BOTTOM;  
  102.         pdfCell3.VerticalAlignment = Element.ALIGN_MIDDLE;  
  103.         pdfCell4.VerticalAlignment = Element.ALIGN_TOP;  
  104.         pdfCell5.VerticalAlignment = Element.ALIGN_MIDDLE;  
  105.         pdfCell6.VerticalAlignment = Element.ALIGN_MIDDLE;  
  106.         pdfCell7.VerticalAlignment = Element.ALIGN_MIDDLE;      
  107.   
  108.         pdfCell4.Colspan = 3;    
  109.   
  110.         pdfCell1.Border = 0;  
  111.         pdfCell2.Border = 0;  
  112.         pdfCell3.Border = 0;  
  113.         pdfCell4.Border = 0;  
  114.         pdfCell5.Border = 0;  
  115.         pdfCell6.Border = 0;  
  116.         pdfCell7.Border = 0;      
  117.   
  118.         //add all three cells into PdfTable  
  119.         pdfTab.AddCell(pdfCell1);  
  120.         pdfTab.AddCell(pdfCell2);  
  121.         pdfTab.AddCell(pdfCell3);  
  122.         pdfTab.AddCell(pdfCell4);  
  123.         pdfTab.AddCell(pdfCell5);  
  124.         pdfTab.AddCell(pdfCell6);  
  125.         pdfTab.AddCell(pdfCell7);  
  126.   
  127.         pdfTab.TotalWidth = document.PageSize.Width - 80f;  
  128.         pdfTab.WidthPercentage = 70;  
  129.         //pdfTab.HorizontalAlignment = Element.ALIGN_CENTER;      
  130.   
  131.         //call WriteSelectedRows of PdfTable. This writes rows from PdfWriter in PdfTable  
  132.         //first param is start row. -1 indicates there is no end row and all the rows to be included to write  
  133.         //Third and fourth param is x and y position to start writing  
  134.         pdfTab.WriteSelectedRows(0, -1, 40, document.PageSize.Height - 30, writer.DirectContent);  
  135.         //set pdfContent value  
  136.   
  137.         //Move the pointer and draw line to separate header section from rest of page  
  138.         cb.MoveTo(40, document.PageSize.Height - 100);  
  139.         cb.LineTo(document.PageSize.Width - 40, document.PageSize.Height - 100);  
  140.         cb.Stroke();  
  141.   
  142.         //Move the pointer and draw line to separate footer section from rest of page  
  143.         cb.MoveTo(40, document.PageSize.GetBottom(50) );  
  144.         cb.LineTo(document.PageSize.Width - 40, document.PageSize.GetBottom(50));  
  145.         cb.Stroke();  
  146.     }  
  147.   
  148.     public override void OnCloseDocument(PdfWriter writer, Document document)  
  149.     {  
  150.         base.OnCloseDocument(writer, document);  
  151.   
  152.         headerTemplate.BeginText();  
  153.         headerTemplate.SetFontAndSize(bf, 12);  
  154.         headerTemplate.SetTextMatrix(0, 0);  
  155.         headerTemplate.ShowText((writer.PageNumber - 1).ToString());  
  156.         headerTemplate.EndText();  
  157.   
  158.         footerTemplate.BeginText();  
  159.         footerTemplate.SetFontAndSize(bf, 12);  
  160.         footerTemplate.SetTextMatrix(0, 0);  
  161.         footerTemplate.ShowText((writer.PageNumber - 1).ToString());  
  162.         footerTemplate.EndText();    
  163.     }  
  164. }