You should write something like that:
PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(DEST));
Document doc = new Document(pdfDoc);
PdfAcroForm form = PdfAcroForm.getAcroForm(pdfDoc, true);
Map<String, PdfFormField> fields = form.getFormFields();
fields.get("Name").setValue("Jeniffer");
fields.get("Company").setValue("iText's next customer");
fields.get("Country").setValue("No Man's Land");
form.flattenFields();
Table table = new Table(UnitValue.createPercentArray(new float[]{1, 15}));
table.addHeaderCell("#");
table.addHeaderCell("description");
for (int i = 1; i <= 150; i++) {
table.addCell(String.valueOf(i));
table.addCell("test " + i);
}
doc.setRenderer(new DocumentRenderer(doc) {
@Override
protected LayoutArea updateCurrentArea(LayoutResult overflowResult) {
LayoutArea area = super.updateCurrentArea(overflowResult);
if (area.getPageNumber() == 1) {
area.getBBox().decreaseHeight(266);
}
return area;
}
});
doc.add(table);
doc.close();
Probably the most interesting part is about extending DocumentRenderer. The instance of this class associated with document handles its layout and overrided method (updateCurrentArea), as the name stands for, updates area for layout.
What is important to mention: All iText5 SO answers are ported in iText7 and you can find them on iText's website: https://developers.itextpdf.com/content/itext-7-examples .