Generate PDF files from Java Standalone/Web Applications dynamically
IText is a freely available Java library from Lowagie.com. The iText library is powerful to generating PDFs.
Pre-requisites:
- Itext-2.1.4.jar (To download http://www.lowagie.com/iText/download.html )
Optional (If we need to align text as traditional format):
1.itext-hyph-xml.jar (To download http://sourceforge.net/project/showfiles.php?group_id=15255&package_id=151860&release_id=326129)
Configuring iText in Eclipse :
- Create a new Java project in Eclipse named like iText .
- Right-click on the iText project in Package Explorer view and select Properties.
- Click Java Build Path. On the Libraries tab, click Add External JARs.
- Browse to the C:\temp directory and select the itext-2.1.4.jar in this directory.
- Click OK.
- com.lowagie.text.Paragraph -- This class represents an indented paragraph.
- com.lowagie.text.Chapter -- This class represents a chapter in the PDF document. It is created using a Paragraph as title and an int as chapter number.
- com.lowagie.text.Font -- This class contains all specifications of a font, such as family of font, size, style, and color. Various fonts are declared as static constants in this class.
- com.lowagie.text.List -- This class represents a list, which, in turn, contains a number of ListItems.
- com.lowagie.text.Table -- This class represents a table that contains cells, ordered in a matrix.
/* Simple HelloWorld.java program */
Step 2: Get a DocWriter instance (in this case, a PdfWriter instance)
Step 4: Add content to the Document.
Document document = new Document(); ------àStep 1
PdfWriter.getInstance(document,new FileOutputStream("HelloWorld.pdf")); --------àStep2
document.open(); -----------------àStep3
document.add(new Paragraph("Hello World")); ---------------àStep4
document.close(); ------------àStep5
let me know if you have any queries on this(IText).
very nice article...it will helps me a lot
ReplyDelete