Suppose that we wanted to create a simple Hello World document:
In iText 7, we could do that like this:
public void createPdf(String dest) throws IOException {
PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
Document document = new Document(pdf);
document.add(new Paragraph("Hello World!"));
document.close();
}
Or, we could even do it like this:
public void createPdf(String dest) throws IOException {
PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
try (Document document = new Document(pdf)) {
document.add(new Paragraph("Hello World!"));
}
}
Source: developers.itextpdf.com and the iText 7: Building Blocks tutorial.