我有一張標題和一張表格供內容使用。我的內容表太長,並且不適合單個頁面。所以我想在每頁後重復我的標題表。我怎樣才能做到這一點?請幫忙。如何在所有頁面上提供重複標題 - iText pdf
這裏是我的代碼
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);
下面有一些重複的顯示內容是動態的,所以我不能告訴多少頁怎麼會在那裏。 我想在所有頁面上重複titleTable。
請提供您的密碼。 –
@TareqMahmood請檢查 – Usr1123
謝謝,現在有人可以幫助你更好。 (不是我,我不是'java'傢伙)。 –