iText is a free Java library for generating PDF documents inside your own applications. The library is easy to use and can produce great results with only little programming. The basic usage is pretty simple. Let’s take a look at a small “Hello World” application:
Document document = new Document(); try { PdfWriter.getInstance(document, new FileOutputStream("output.pdf")); document.open(); document.add(new Paragraph("Hello World")); } catch (Exception e) { } document.close();
Creating a new document object will initialize a new PDF document with A4 dimensions. The PdfWriter will be used to write the resulting document to an OutputStream, which is in the above example a file. After opening the document you can just add new paragraphs to the document.