I have a table for title and a table for content. My content table is too long and doesn't fit in a single page. So I want to repeat my title table after each page. How can I achieve this? Please help.
Here is my code
File tempFile = File.createTempFile("progress", "tmp");
Document document = new Document(PageSize.A4);
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(tempFile));
document.setMargins(6, 6, 36, 36);
document.setMarginMirroring(true);
document.open();
PdfPTable titleTable = new PdfPTable(new float[] { 18f });
// Image img = Image.getInstance(uploadFolder + "/logo.jpg");
Font titleFont = new Font(getBaseFont(), 12f, Font.BOLD);
Font tHeadFont = new Font(getBaseFont(), 10f, Font.BOLD);
Font contentFont = new Font(getBaseFont(), 10f);
// img.scalePercent(50);
titleTable.setWidthPercentage(100);
titleTable.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
titleTable.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
// titleTable.addCell(new Paragraph(new Chunk(img, 5, -5)));
document.add(gutter());
titleTable.addCell(new Paragraph("Title", titleFont));
document.add(titleTable);
document.add(gutter());
document.add(gutter());
PdfPTable comTable = new PdfPTable(new float[] { 6f, 4f, 2f, 3f, 6f, 3f });
PdfPCell cell1 = new PdfPCell(new Paragraph("Module", tHeadFont));
cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);
cell1.setPaddingBottom(4);
comTable.addCell(cell1);
PdfPCell cell2 = new PdfPCell(new Paragraph("Name", tHeadFont));
cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
cell2.setVerticalAlignment(Element.ALIGN_MIDDLE);
cell2.setPaddingBottom(4);
comTable.addCell(cell2);
PdfPCell cell3 = new PdfPCell(new Paragraph("Serial", tHeadFont));
cell3.setHorizontalAlignment(Element.ALIGN_CENTER);
cell3.setVerticalAlignment(Element.ALIGN_MIDDLE);
cell3.setPaddingBottom(4);
comTable.addCell(cell3);
PdfPCell cell4 = new PdfPCell(new Paragraph("Lesson", tHeadFont));
cell4.setHorizontalAlignment(Element.ALIGN_CENTER);
cell4.setVerticalAlignment(Element.ALIGN_MIDDLE);
cell4.setPaddingBottom(4);
comTable.addCell(cell4);
PdfPCell cell5 = new PdfPCell(new Paragraph("Topic", tHeadFont));
cell5.setHorizontalAlignment(Element.ALIGN_CENTER);
cell5.setVerticalAlignment(Element.ALIGN_MIDDLE);
cell5.setPaddingBottom(4);
comTable.addCell(cell5);
PdfPCell cell6 = new PdfPCell(new Paragraph("No.of Lessons", tHeadFont));
cell6.setHorizontalAlignment(Element.ALIGN_CENTER);
cell6.setVerticalAlignment(Element.ALIGN_MIDDLE);
cell6.setPaddingBottom(4);
comTable.addCell(cell6);
There are some iterations below for displaying content which is dynamic so I can't tell how many pages will be there. I want titleTable to be repeated on all pages.