To create a new page in a PDF document using iText in Java, you can use the document.newPage()
method of the com.itextpdf.kernel.pdf.PdfDocument
class.
Here is an example of how to use this method to create a new page in a PDF document:
import com.itextpdf.kernel.pdf.PdfDocument; import com.itextpdf.kernel.pdf.PdfWriter; import com.itextpdf.layout.Document; import com.itextpdf.layout.element.Paragraph; ... // Create a PDF document and a writer PdfDocument pdfDoc = new PdfDocument(new PdfWriter("output.pdf")); Document doc = new Document(pdfDoc); // Add some content to the document doc.add(new Paragraph("Page 1")); // Create a new page doc.newPage(); // Add some more content to the document doc.add(new Paragraph("Page 2")); // Close the document doc.close();
This code creates a new PDF document and adds two pages to it, each containing a simple paragraph of text. The newPage()
method creates a new page in the document and moves the cursor to the top of the page, so that you can add new content to the page.
For more information on using iText to create PDF documents in Java, you can refer to the iText documentation or other online resources.