title: Add Header and Footer for PDF using iTextsharp
body: <p>How can I add header and footer for each page in the pdf.</p>
  
  <p>Headed will contain just a text
  Footer will contain a text and pagination for pdf (Page : 1 of 4)</p>
  
  <p>How is this possible ? I tried to add the below line, but header does not show up in pdf.</p>
  
  <pre><code>document.AddHeader("Header", "Header Text");
  </code></pre>
  
  <p>This the code I am using for generation PDF :</p>
  
  <pre><code>   protected void GeneratePDF_Click(object sender, EventArgs e)
      {
          DataTable dt = getData(); 
  
              Response.ContentType = "application/pdf";
              Response.AddHeader("content-disposition", "attachment;filename=Locations.pdf");
              Response.Cache.SetCacheability(HttpCacheability.NoCache);
  
              Document document = new Document();
  
              PdfWriter.GetInstance(document, Response.OutputStream);
  
              document.Open();
  
              iTextSharp.text.Font font5 = iTextSharp.text.FontFactory.GetFont(FontFactory.COURIER , 8);
  
              PdfPTable table = new PdfPTable(dt.Columns.Count);
              PdfPRow row = null;
              float[] widths = new float[] { 6f, 6f, 2f, 4f, 2f };
  
              table.SetWidths(widths);
  
              table.WidthPercentage = 100;
              int iCol = 0;
              string colname = "";
              PdfPCell cell = new PdfPCell(new Phrase("Locations"));
  
              cell.Colspan = dt.Columns.Count;
  
              foreach (DataColumn c in dt.Columns)
              {
  
                  table.AddCell(new Phrase(c.ColumnName, font5));
              }
  
              foreach (DataRow r in dt.Rows)
              {
                  if (dt.Rows.Count &gt; 0)
                  {
                      table.AddCell(new Phrase(r[0].ToString(), font5));
                      table.AddCell(new Phrase(r[1].ToString(), font5));
                      table.AddCell(new Phrase(r[2].ToString(), font5));
                      table.AddCell(new Phrase(r[3].ToString(), font5));
                      table.AddCell(new Phrase(r[4].ToString(), font5));
                  }
              }
              document.Add(table);
              document.Close();
  
              Response.Write(document);
              Response.End();
          } 
      }
  </code></pre>