iText PDF Generator

Here I am going to explain how to creat a simple pdf file with java pdf library called iText. There are other well known similar frameworks like Apache cocoon, and PDFBox which are good and mature. But I choose to use iText, because of its popularity and support, and infact it is very good for pdf generation from scratch.

iText generates pdf dynamically, ideally this framework is very useful for developer who wants to enhance thier web application developement with dyanamic pdf generation based on user inputs on the fly.

Using iText, you can able to generate, maniulate and parse the pdf file. And, please remember, this is not an end user tool to view pdf files. To view the generated pdf files you should have installed Acrobat PDF software from Adobe Systems.

Enough said, we will get into the code and make our hands diryt, okay.
Download latest iText jar file Click here , and put it in your project’s classpath.
First thing, you need is to create document object

com.lowagie.text.Document document = new com.lowagie.text.Document();

Second, create PDFWriter object by passing document, and give pdf file name that you want to create

com.lowagie.text.pdf.PdfWriter.PdfWriter.getInstance(document, new
FileOutputStream(”HelloWorld.pdf”));

Third, open the document to start writing onto it

document.open();

Fourth, add a paragraph to your document

document.add(new Paragraph(”Hello Ramraj….”));

Finally, you need to close the document

document.close();

That’s it, It’s that simple to create pdf using iText.

Probably some time later I will attach the full source code here:-)

Enough staying at office, I gotta go home, bye


Browse Realted Articles

    Bookmark and Share

    One Response to “iText PDF Generator”

    Rakesh says on Feb Fri, 2009 at 05:46:00 am

    good information 0n iText pdf generator, Thanks ramraj.

    Regards.
    http://www.StudyWell.info

    Leave a Reply