title: How to repeat the last 5 rows of a table on the next page?
body: <p>I've been searching for an answer for this but cant find a good tutorial. I'm using Java itext to generate a pdf. I have a table which prints over 50 rows which eats around 2 pages. I need to print the last 5 rows of the previous page to the next page before continuing printing the list.</p>
  
  <p><code>Example:
  row 31
  row 32
  row 33
  row 34
  row 35
  row 36
  --end of page 1--
  row 32
  row 33
  row 34
  row 35
  row 36
  row 37</code></p>
  
  <p>Any idea on how to do this?</p>
  
  <p><code>Currently it prints like this:
  row 35
  row 36
  --end of page 1--
  row 37
  row 38</code></p>
  
  <p>Code: (Focus on start loop and never mind those headers)</p>
  
  <pre><code>PdfPTable table = new PdfPTable(4);
  table.setWidthPercentage(97);
  table.setWidths(new float[] {10, 45, 25, 25});
  
  PdfPCell c1 = new PdfPCell(new Phrase("Logo", FontFactory.getFont(FontFactory.TIMES_ROMAN, 14)));
  c1.setPadding(5);
  c1.setHorizontalAlignment(Element.ALIGN_LEFT);
  c1.setVerticalAlignment(Element.ALIGN_CENTER);
  c1.setBorder(0);
  c1.setColspan(4);
  table.addCell(c1);
  
  c1 = new PdfPCell(new Phrase("09/01/2013 - 09/15/2013", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12)));
  c1.setPadding(5);
  c1.setHorizontalAlignment(Element.ALIGN_LEFT);
  c1.setVerticalAlignment(Element.ALIGN_CENTER);
  c1.setBorder(0);
  c1.setColspan(4);
  c1.setPaddingBottom(20);
  table.addCell(c1);
  
  //start header
  c1 = new PdfPCell(new Phrase(" ", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12)));
  c1.setPaddingBottom(5);
  c1.setHorizontalAlignment(Element.ALIGN_LEFT);
  c1.setBackgroundColor(WebColors.getRGBColor("#99CCFF"));
  c1.setBorder(1);
  table.addCell(c1);
  
  c1 = new PdfPCell(new Phrase("Name", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12)));
  c1.setPaddingBottom(5);
  c1.setHorizontalAlignment(Element.ALIGN_LEFT);
  c1.setBackgroundColor(WebColors.getRGBColor("#99CCFF"));
  c1.setBorder(1);
  table.addCell(c1);
  
  c1 = new PdfPCell(new Phrase("Number", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12)));
  c1.setPaddingBottom(5);
  c1.setHorizontalAlignment(Element.ALIGN_LEFT);
  c1.setBackgroundColor(WebColors.getRGBColor("#99CCFF"));
  c1.setBorder(1);
  table.addCell(c1);
  
  c1 = new PdfPCell(new Phrase("Amount", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12)));
  c1.setPaddingBottom(5);
  c1.setHorizontalAlignment(Element.ALIGN_RIGHT);
  c1.setBackgroundColor(WebColors.getRGBColor("#99CCFF"));
  c1.setBorder(1);
  table.addCell(c1);
  //end header
  
  //start for loop
  for(int a=0; a&lt;50; a++)
  {
      int border=0;
      if(a%5==0)
      {border=1;}
  
      c1 = new PdfPCell(new Phrase((a+1)+"", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12)));
      c1.setHorizontalAlignment(Element.ALIGN_LEFT);
      c1.setBorder(border);
      c1.setPaddingBottom(5);
      table.addCell(c1);
  
      c1 = new PdfPCell(new Phrase("Last Name, First Name", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12)));
      c1.setHorizontalAlignment(Element.ALIGN_LEFT);
      c1.setBorder(border);
      c1.setPaddingBottom(5);
      table.addCell(c1);
  
      c1 = new PdfPCell(new Phrase("1", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12)));
      c1.setHorizontalAlignment(Element.ALIGN_CENTER);
      c1.setBorder(border);
      c1.setPaddingBottom(5);
      table.addCell(c1);
  
      c1 = new PdfPCell(new Phrase("1", FontFactory.getFont(FontFactory.TIMES_ROMAN, 12)));
      c1.setHorizontalAlignment(Element.ALIGN_RIGHT);
      c1.setBorder(border);
      c1.setPaddingBottom(5);
      table.addCell(c1);
  
  
  }
  //end for loop
  
  subCatPart.add(table);
  </code></pre>