title: Fill table from left to right using iTextSharp
body: <p>I am generating a PDF using iTextSharp.dll in C#.net.</p>
  
  <p><strong>Requirement:</strong></p>
  
  <p>I am in need of creating a PDF of Directory with information. My PDF Document contains the following sections in a <strong>single page</strong>: </p>
  
  <ol>
  <li><p>Header (Banner Image)</p></li>
  <li><p>Title (As Directory)</p></li>
  <li><p>Contents (Contains directory information)</p>
  
  <p>3.1. Left side contents</p>
  
  <p>3.2. Right side contents</p></li>
  <li><p>Footer (Contains page number)</p></li>
  </ol>
  
  <p>Below is the picture or layout of how the document will look like:<a href="https://i.stack.imgur.com/vQrE0.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vQrE0.jpg" alt="enter image description here"></a></p>
  
  <p><em>From the above, Header, Title and Footer will be same for all the pages.</em></p>
  
  <p><strong>Detailed explanation about content table section:</strong></p>
  
  <p>Content table section holds the people information. We have the following type of information to be filled.</p>
  
  <ol>
  <li>Image</li>
  <li>Person Details with address.</li>
  </ol>
  
  <p>The process of filling the information is as follows:</p>
  
  <ol>
  <li>First fill the Images and Person Details in the <strong><em>Left Content Table</em></strong>.</li>
  <li>While adding the content, if the <strong><em>left content table</em></strong> reaches the footer or if it exceeds the footer of a page, then move to the <strong><em>Right Content Table</em></strong></li>
  <li>On filling the <strong><em>right content table</em></strong>, if it exceeds the footer, then move on to the next page and proceed with the <strong><em>left content table</em></strong> of the new page.</li>
  </ol>
  
  <p><strong>What I tried:</strong></p>
  
  <p>I tried to complete this approach for a single page. </p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          ///// ---- Table creation in PDF using iTextSharp -----///
  
  
  
          /// Creating a document
          ///
          Document document = new Document(PageSize.A4, 10, 10, 10, 10);
  
          if (File.Exists("F:\\Output.pdf"))
              File.Delete("F:\\Output.pdf");
          FileStream pdfFileStream = new FileStream("F:\\Output.pdf", FileMode.Create);
          string bannerPath = "F:\\banner.png";
          iTextSharp.text.Image bannerImage = iTextSharp.text.Image.GetInstance(bannerPath);
          bannerImage.ScaleToFit(50f, 90f);
          using (PdfWriter pdfWriter = PdfWriter.GetInstance(document, pdfFileStream))
          {
  
              document.Open();
              PdfContentByte cb = pdfWriter.DirectContent;
  
  
              ///// ---- Table creation in PDF using iTextSharp -----///
  
              PdfPTable documentTable = new PdfPTable(1);
  
              documentTable.HorizontalAlignment = 0;//0=Left, 1=Centre, 2=Right
              documentTable.TotalWidth = 570;
              documentTable.LockedWidth = true;
              documentTable.DefaultCell.Border = Rectangle.NO_BORDER;
              documentTable.SplitLate = false;
              documentTable.SplitRows = true;
              //firstRowTable first column
  
              //Header name table
              PdfPTable headerTable = new PdfPTable(1);
              documentTable.HorizontalAlignment = 1;
              headerTable.TotalWidth = 570;
              headerTable.LockedWidth = true;
              headerTable.DefaultCell.Border = Rectangle.NO_BORDER;
  
              //Add Image to the cell with auto fit true.
              PdfPCell headerCell = new PdfPCell(bannerImage);
              headerTable.AddCell(headerCell);
              documentTable.AddCell(headerTable);
  
  
              PdfPTable titleTable = new PdfPTable(1);
              titleTable.HorizontalAlignment = 0;//0=Left, 1=Centre, 2=Right
              titleTable.TotalWidth = 200;
              titleTable.LockedWidth = true;
  
              //Title.
              Phrase titlePhrase = new Phrase();
              var FontColour = new BaseColor(31, 73, 125);
              var normalFont = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 15, FontColour);
              Chunk titleChunk = new Chunk("Physician Directory", normalFont);
              titlePhrase.Add(titleChunk);
              PdfPCell cell1 = new PdfPCell(titlePhrase);
              cell1.Border = 0;//No border
              titleTable.AddCell(cell1);
  
              documentTable.AddCell(titleTable);
  
              #region "Physician's table"
  
              //Create Physician table.
              PdfPTable physicianTable = new PdfPTable(2);
              physicianTable.HorizontalAlignment = 0;//0=Left, 1=Centre, 2=Right
              physicianTable.TotalWidth = 570;
              physicianTable.LockedWidth = true;
              physicianTable.DefaultCell.Border = Rectangle.NO_BORDER;
  
              #region "Physician's left side table"
  
              //Create Physician table.
              PdfPTable physicianLeftTable = new PdfPTable(2);
              physicianLeftTable.HorizontalAlignment = 0;//0=Left, 1=Centre, 2=Right
              physicianLeftTable.TotalWidth = 285;
              physicianLeftTable.LockedWidth = true;
              physicianLeftTable.DefaultCell.Border = Rectangle.NO_BORDER;
  
              #region "Physician's left side table contents 1"
  
              #region "Physician's column1"
  
              string doctor1Path = "F:\\Doctor1.jpg";
              iTextSharp.text.Image doctor1Image = iTextSharp.text.Image.GetInstance(doctor1Path);
              doctor1Image.ScaleToFit(50f, 90f);
              PdfPCell physicianLeftTableContent1Column1 = new PdfPCell(doctor1Image);
  
              physicianLeftTableContent1Column1.Border = Rectangle.NO_BORDER;
              physicianLeftTable.AddCell(physicianLeftTableContent1Column1);
              #endregion "Physician's column1"
  
              #region "Physician's column2"
              Phrase paraPhrase = new Phrase();
              var nameChunkFontColour = new BaseColor(31, 73, 125);
              var nameChunkNormalFont = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8, nameChunkFontColour);
              Chunk nameChunk = new Chunk("Name1\n", nameChunkNormalFont);
              paraPhrase.Add(new Paragraph(nameChunk));
  
              var doctorType1ChunkNormalFont = FontFactory.GetFont(FontFactory.HELVETICA_OBLIQUE, 8);
              Chunk doctorType1Chunk = new Chunk("Pediatric Neurologist,\n", doctorType1ChunkNormalFont);
              paraPhrase.Add(new Paragraph(doctorType1Chunk));
  
              var doctorType2ChunkNormalFont = FontFactory.GetFont(FontFactory.HELVETICA_OBLIQUE, 8);
              Chunk doctorType2Chunk = new Chunk("Headache Medicine\n", doctorType1ChunkNormalFont);
              paraPhrase.Add(new Paragraph(doctorType2Chunk));
  
              paraPhrase.Add(new Paragraph("\n"));
  
              var healthGroupChunkNormalFont = FontFactory.GetFont(FontFactory.HELVETICA, 8);
              Chunk healthGroupChunk = new Chunk("Health Medical Group\n", healthGroupChunkNormalFont);
              paraPhrase.Add(new Paragraph(healthGroupChunk));
  
              var addressLine1ChunkNormalFont = FontFactory.GetFont(FontFactory.HELVETICA, 8);
              Chunk addressLine1Chunk = new Chunk("Pediatric Neurology, \n", addressLine1ChunkNormalFont);
              paraPhrase.Add(new Paragraph(addressLine1Chunk));
  
              var addressLine2ChunkNormalFont = FontFactory.GetFont(FontFactory.HELVETICA, 8);
              Chunk addressLine2Chunk = new Chunk("701 Road\n", addressLine2ChunkNormalFont);
              paraPhrase.Add(new Paragraph(addressLine2Chunk));
  
              var addressLine3ChunkNormalFont = FontFactory.GetFont(FontFactory.HELVETICA, 8);
              Chunk addressLine3Chunk = new Chunk("Village, IL 7\n", addressLine3ChunkNormalFont);
              paraPhrase.Add(new Paragraph(addressLine3Chunk));
  
              var zipCodeChunkNormalFont = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8);
              Chunk zipCodeChunk = new Chunk("123-456 -789\n", zipCodeChunkNormalFont);
              paraPhrase.Add(new Paragraph(zipCodeChunk));
  
              paraPhrase.Add(new Paragraph("\n"));
  
              var healthGroup1ChunkNormalFont = FontFactory.GetFont(FontFactory.HELVETICA, 8);
              Chunk healthGroup1Chunk = new Chunk("Health Medical Group\n", healthGroup1ChunkNormalFont);
              paraPhrase.Add(new Paragraph(healthGroup1Chunk));
  
              var addressLine1ChunkNormalFont1 = FontFactory.GetFont(FontFactory.HELVETICA, 8);
              Chunk addressLine1Chunk1 = new Chunk("Pediatric Neurology, \n", addressLine1ChunkNormalFont1);
              paraPhrase.Add(new Paragraph(addressLine1Chunk1));
  
              var addressLine2ChunkNormalFont1 = FontFactory.GetFont(FontFactory.HELVETICA, 8);
              Chunk addressLine2Chunk1 = new Chunk("701 Road\n", addressLine2ChunkNormalFont1);
              paraPhrase.Add(new Paragraph(addressLine2Chunk1));
  
              var addressLine3ChunkNormalFont1 = FontFactory.GetFont(FontFactory.HELVETICA, 8);
              Chunk addressLine3Chunk1 = new Chunk("Village, IL 7\n", addressLine3ChunkNormalFont1);
              paraPhrase.Add(new Paragraph(addressLine3Chunk1));
  
              var zipCodeChunkNormalFont1 = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8);
              Chunk zipCodeChunk1 = new Chunk("123-456 -7890\n", zipCodeChunkNormalFont1);
              paraPhrase.Add(new Paragraph(zipCodeChunk1));
  
              paraPhrase.Add(new Paragraph("\n"));
              var healthGroup2ChunkNormalFont = FontFactory.GetFont(FontFactory.HELVETICA, 8);
              Chunk healthGroup2Chunk = new Chunk("Health Medical Group\n", healthGroup2ChunkNormalFont);
              paraPhrase.Add(new Paragraph(healthGroup2Chunk));
  
              var addressLine1ChunkNormalFont2 = FontFactory.GetFont(FontFactory.HELVETICA, 8);
              Chunk addressLine1Chunk2 = new Chunk("Pediatric Neurology\n", addressLine1ChunkNormalFont2);
              paraPhrase.Add(new Paragraph(addressLine1Chunk2));
  
              var addressLine2ChunkNormalFont2 = FontFactory.GetFont(FontFactory.HELVETICA, 8);
              Chunk addressLine2Chunk2 = new Chunk("701 Road\n", addressLine2ChunkNormalFont2);
              paraPhrase.Add(new Paragraph(addressLine2Chunk2));
  
              var addressLine3ChunkNormalFont2 = FontFactory.GetFont(FontFactory.HELVETICA, 8);
              Chunk addressLine3Chunk2 = new Chunk("Village, IL 12345\n", addressLine3ChunkNormalFont2);
              paraPhrase.Add(new Paragraph(addressLine3Chunk2));
  
              var zipCodeChunkNormalFont2 = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8);
              Chunk zipCodeChunk2 = new Chunk("123-456 -7890\n", zipCodeChunkNormalFont2);
              paraPhrase.Add(new Paragraph(zipCodeChunk2));
  
              paraPhrase.Add(new Paragraph("\n"));
  
              var healthGroup3ChunkNormalFont = FontFactory.GetFont(FontFactory.HELVETICA, 8);
              Chunk healthGroup3Chunk = new Chunk("Health Medical Group\n", healthGroup3ChunkNormalFont);
              paraPhrase.Add(new Paragraph(healthGroup3Chunk));
  
              var addressLine1ChunkNormalFont3 = FontFactory.GetFont(FontFactory.HELVETICA, 8);
              Chunk addressLine1Chunk3 = new Chunk("Pediatric Neurology\n", addressLine1ChunkNormalFont3);
              paraPhrase.Add(new Paragraph(addressLine1Chunk3));
  
              var addressLine2ChunkNormalFont3 = FontFactory.GetFont(FontFactory.HELVETICA, 8);
              Chunk addressLine2Chunk3 = new Chunk("701 Road\n", addressLine2ChunkNormalFont3);
              paraPhrase.Add(new Paragraph(addressLine2Chunk3));
  
              var addressLine3ChunkNormalFont3 = FontFactory.GetFont(FontFactory.HELVETICA, 8);
              Chunk addressLine3Chunk3 = new Chunk("Village, IL 12345\n", addressLine3ChunkNormalFont3);
              paraPhrase.Add(new Paragraph(addressLine3Chunk3));
  
              var zipCodeChunkNormalFont3 = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8);
              Chunk zipCodeChunk3 = new Chunk("123-456 -7890\n", zipCodeChunkNormalFont3);
              paraPhrase.Add(new Paragraph(zipCodeChunk3));
  
              paraPhrase.Add(new Paragraph("\n"));
  
              var healthGroup4ChunkNormalFont = FontFactory.GetFont(FontFactory.HELVETICA, 8);
              Chunk healthGroup4Chunk = new Chunk("Health Medical Group\n", healthGroup4ChunkNormalFont);
              paraPhrase.Add(new Paragraph(healthGroup4Chunk));
  
              var addressLine1ChunkNormalFont4 = FontFactory.GetFont(FontFactory.HELVETICA, 8);
              Chunk addressLine1Chunk4 = new Chunk("Pediatric Neurology\n", addressLine1ChunkNormalFont4);
              paraPhrase.Add(new Paragraph(addressLine1Chunk4));
  
              var addressLine2ChunkNormalFont4 = FontFactory.GetFont(FontFactory.HELVETICA, 8);
              Chunk addressLine2Chunk4 = new Chunk("Road\n", addressLine2ChunkNormalFont4);
              paraPhrase.Add(new Paragraph(addressLine2Chunk4));
  
              var addressLine3ChunkNormalFont4 = FontFactory.GetFont(FontFactory.HELVETICA, 8);
              Chunk addressLine3Chunk4 = new Chunk("Village, IL 12345\n", addressLine3ChunkNormalFont4);
              paraPhrase.Add(new Paragraph(addressLine3Chunk4));
  
              var zipCodeChunkNormalFont4 = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8);
              Chunk zipCodeChunk4 = new Chunk("123-456 -7890\n", zipCodeChunkNormalFont4);
              paraPhrase.Add(new Paragraph(zipCodeChunk4));
  
              paraPhrase.Add(new Paragraph("\n"));
  
              PdfPCell physicianLeftTableContent1Column2 = new PdfPCell(paraPhrase);
              physicianLeftTableContent1Column2.Border = Rectangle.NO_BORDER;
              physicianLeftTable.AddCell(physicianLeftTableContent1Column2);
  
              int count = pdfWriter.PageNumber;
  
              #endregion "Physician's column2"
  
              //physicianLeftTable.AddCell(physicianLeftTableContent1);
  
              #endregion "Physician's left side content table"
  
              #region "Physician's left side table contents 2"
              //Create left side table.
              PdfPTable physicianLeftTableContent2 = new PdfPTable(2);
              physicianLeftTableContent2.HorizontalAlignment = 0;//0=Left, 1=Centre, 2=Right
              physicianLeftTableContent2.TotalWidth = 142.5f;
              physicianLeftTableContent2.LockedWidth = true;
              physicianLeftTableContent2.DefaultCell.Border = Rectangle.NO_BORDER;
  
              #region "Physician's column1"
  
              string doctor2Path = "F:\\Image2.jpg";
              iTextSharp.text.Image doctor2Image = iTextSharp.text.Image.GetInstance(doctor2Path);
              doctor2Image.ScaleToFit(50f, 90f);
              PdfPCell physicianLeftTableContent2Column1 = new PdfPCell(doctor2Image);
  
              physicianLeftTableContent2Column1.Border = Rectangle.NO_BORDER;
              physicianLeftTable.AddCell(physicianLeftTableContent2Column1);
  
              #endregion "Physician's column1"
  
              #region "Physician's column2"
              Phrase paraPhrase1 = new Phrase();
              var nameChunkFontColour1 = new BaseColor(31, 73, 125);
              var nameChunkNormalFont1 = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8, nameChunkFontColour1);
              Chunk nameChunk1 = new Chunk("Name1 M.D.\n", nameChunkNormalFont1);
              paraPhrase.Add(new Paragraph(nameChunk1));
  
              var doctorType3ChunkNormalFont = FontFactory.GetFont(FontFactory.HELVETICA_OBLIQUE, 8);
              Chunk doctorType3Chunk = new Chunk("General Surgery\n", doctorType3ChunkNormalFont);
              paraPhrase.Add(new Paragraph(doctorType3Chunk));
  
              paraPhrase.Add(new Paragraph("\n"));
  
              var healthGroupChunkNormalFont5 = FontFactory.GetFont(FontFactory.HELVETICA, 8);
              Chunk healthGroupChunk5 = new Chunk("Medical Center\n", healthGroupChunkNormalFont5);
              paraPhrase.Add(new Paragraph(healthGroupChunk5));
  
              var addressLine1ChunkNormalFont5 = FontFactory.GetFont(FontFactory.HELVETICA, 8);
              Chunk addressLine1Chunk5 = new Chunk("First Avenue\n", addressLine1ChunkNormalFont5);
              paraPhrase.Add(new Paragraph(addressLine1Chunk5));
  
              var addressLine2ChunkNormalFont5 = FontFactory.GetFont(FontFactory.HELVETICA, 8);
              Chunk addressLine2Chunk5 = new Chunk("Room 3230\n", addressLine2ChunkNormalFont5);
              paraPhrase.Add(new Paragraph(addressLine2Chunk5));
  
              var addressLine3ChunkNormalFont5 = FontFactory.GetFont(FontFactory.HELVETICA, 8);
              Chunk addressLine3Chunk5 = new Chunk("IL 60153\n", addressLine3ChunkNormalFont5);
              paraPhrase.Add(new Paragraph(addressLine3Chunk5));
  
              var zipCodeChunkNormalFont5 = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8);
              Chunk zipCodeChunk5 = new Chunk("123-456 -7890\n", zipCodeChunkNormalFont5);
              paraPhrase.Add(new Paragraph(zipCodeChunk5));
  
              paraPhrase.Add(new Paragraph("\n"));
  
              var healthGroupChunkNormalFont6 = FontFactory.GetFont(FontFactory.HELVETICA, 8);
              Chunk healthGroupChunk6 = new Chunk("Medical Center\n", healthGroupChunkNormalFont6);
              paraPhrase.Add(new Paragraph(healthGroupChunk6));
  
              var addressLine1ChunkNormalFont6 = FontFactory.GetFont(FontFactory.HELVETICA, 8);
              Chunk addressLine1Chunk6 = new Chunk("First Avenue\n", addressLine1ChunkNormalFont6);
              paraPhrase.Add(new Paragraph(addressLine1Chunk6));
  
              var addressLine2ChunkNormalFont6 = FontFactory.GetFont(FontFactory.HELVETICA, 8);
              Chunk addressLine2Chunk6 = new Chunk("Room 3230\n", addressLine2ChunkNormalFont6);
              paraPhrase.Add(new Paragraph(addressLine2Chunk6));
  
              var addressLine3ChunkNormalFont6 = FontFactory.GetFont(FontFactory.HELVETICA, 8);
              Chunk addressLine3Chunk6 = new Chunk("IL 60153\n", addressLine3ChunkNormalFont6);
              paraPhrase.Add(new Paragraph(addressLine3Chunk6));
  
              var zipCodeChunkNormalFont6 = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8);
              Chunk zipCodeChunk6 = new Chunk("123-456 -7890\n", zipCodeChunkNormalFont6);
              paraPhrase.Add(new Paragraph(zipCodeChunk6));
  
  
              PdfPCell physicianLeftTableContent2Column2 = new PdfPCell(paraPhrase);
              physicianLeftTableContent2Column2.Border = Rectangle.NO_BORDER;
              physicianLeftTable.AddCell(physicianLeftTableContent2Column2);
  
              #endregion "Physician's column2"
  
              //physicianLeftTable.AddCell(physicianLeftTableContent2);
  
              #endregion "Physician's left side content table"
  
              int count1 = pdfWriter.PageNumber;
              //Add the left side physician table.
              physicianTable.AddCell(physicianLeftTable);
  
              #endregion "Physician's left side table"
  
              #region "Physician's right side table"
  
              //Create Physician table.
              PdfPTable physicianRightTable = new PdfPTable(2);
              physicianRightTable.HorizontalAlignment = 0;//0=Left, 1=Centre, 2=Right
              physicianRightTable.TotalWidth = 285;
              physicianRightTable.LockedWidth = true;
              physicianRightTable.DefaultCell.Border = Rectangle.NO_BORDER;
  
              #region "Physician's right side table contents 1"
  
              //Create right side table content.
              PdfPTable physicianRightTableContent1 = new PdfPTable(2);
              physicianRightTableContent1.HorizontalAlignment = 0;//0=Left, 1=Centre, 2=Right
              physicianRightTableContent1.TotalWidth = 142.5f;
              physicianRightTableContent1.LockedWidth = true;
              physicianRightTableContent1.DefaultCell.Border = Rectangle.NO_BORDER;
  
              #region "Physician's column1"
  
              string doctor3Path = "F:\\Image2.jpg";
              iTextSharp.text.Image doctor3Image = iTextSharp.text.Image.GetInstance(doctor3Path);
              doctor3Image.ScaleToFit(50f, 90f);
              PdfPCell physicianRightTableContent1Column1 = new PdfPCell(doctor3Image);
  
              physicianRightTableContent1Column1.Border = Rectangle.NO_BORDER;
              physicianRightTable.AddCell(physicianRightTableContent1Column1);
              #endregion "Physician's column1"
  
              //Add the right side physician table.
              //physicianRightTable.AddCell(physicianRightTableContent1);
  
              #endregion "Physician's right side table contents"
  
              #region "Physician's right side table contents 2"
  
              //Create right side table content.
              PdfPTable physicianRightTableContent2 = new PdfPTable(2);
              physicianRightTableContent2.HorizontalAlignment = 0;//0=Left, 1=Centre, 2=Right
              physicianRightTableContent2.TotalWidth = 142.5f;
              physicianRightTableContent2.LockedWidth = true;
              physicianRightTableContent2.DefaultCell.Border = Rectangle.NO_BORDER;
  
              #region "Physician's column1"
  
              string doctor4Path = "F:\\Image1.jpg";
              iTextSharp.text.Image doctor4Image = iTextSharp.text.Image.GetInstance(doctor4Path);
              doctor4Image.ScaleToFit(50f, 90f);
              PdfPCell physicianRightTableContent2Column1 = new PdfPCell(doctor3Image);
  
              physicianRightTableContent1Column1.Border = Rectangle.NO_BORDER;
              physicianRightTableContent1.AddCell(physicianRightTableContent2Column1);
              #endregion "Physician's column1"
  
              //Add the left side physician table.
              physicianRightTable.AddCell(physicianRightTableContent2);
  
              //Add the right side physician table.
              //physicianRightTable.AddCell(new Phrase("Hi"));
  
              #endregion "Physician's right side table contents 2"
  
              //Add the left side physician table.
              physicianTable.AddCell(physicianRightTable);
  
              #endregion "Physician's right side table"
  
              //Add physician table to the document table.
              documentTable.AddCell(physicianTable);
  
              #endregion "Physician's table"
  
              document.Add(documentTable);
  
              document.Close();
          }
  
  
          Console.WriteLine("Completed");
  
          //if (File.Exists("F:\\Output.pdf"))
          //    File.Open("F:\\Output.pdf", FileMode.Open);
      }
  
  }
  </code></pre>
  
  <p><strong>What I need:</strong></p>
  
  <ol>
  <li>Move the contents to the <strong>Right Content Table</strong> if <strong>Left Content Table</strong> reaches the end of the document.</li>
  <li>Move the content to the next page if the <strong>Right Content Table</strong> reaches the end of the document and starts writing contents in the <strong>Left Content Table</strong> of the new page.</li>
  </ol>
  
  <p><strong>NOTE:</strong></p>
  
  <p><em>Since I have no footer setup in the above code, I am trying to find the End of the document. I am stuck with finding whether the Content Table reaches the End of the document or not.</em></p>