Easy to Learn Java: Programming Articles, Examples and Tips

Start with Java in a few days with Java Lessons or Lectures

Home

Code Examples

Java Tools

More Java Tools!

Java Forum

All Java Tips

Books

Submit News
Search the site here...
Search...
 

iText › Click to download › Updated Info




Main Page | Details | Download Now | History | Statistics | Promote | Tell a Friend

Category Reporting
Submitted by
admin
Author's Name Bruno Lowagie
Homepage www.lowagie.com/iText/
Version 1.x
Published
Thu Sep 07, 2006 5:03 am

Description

The iText classes are very useful for people who need to generate read-only, platform independent do*****ents containing text, lists, tables and images. The library is especially useful in combination with Java (TM) technology-based Servlets: The look and feel of HTML is browser dependent; with iText and PDF you can control exactly how your servlet's output will look.



iText is a library that allows you to generate PDF files on the fly.

The iText classes are very useful for people who need to generate read-only, platform independent documents containing text, lists, tables and images. The library is especially useful in combination with Java(TM) technology-based Servlets: The look and feel of HTML is browser dependent; with iText and PDF you can control exactly how your servlet's output will look.

iText requires JDK 1.4. It's available for free under a multiple license: MPL and LGPL.

Introduction

 You will find lots of code samples in the online tutorial iText by Example, but for a nice and simple introduction to the tool, please the articles about iText that was published on the site of PDFDev, AdobePress and IBM (Note that the IBM article was translated into Japanese Chinese, and Korean). More experienced iText users will certainly benefit from the article published on O'Reilly Network. Please keep an eye on the news column or on my blog: the Manning book on iText is nearly finished!

Technical Requirements
In order to be able to use these classes you should be acquainted with JAVA (TM) programming.
You'll also need the following Software:
 
  • The Java Development Kit (JDK) 1.4 (or any later version) from Sun Microsystems Incorporated.
    If for some reason the library should have to work with an earlier version of the JDK, you will have to compile a slightly altered version of the source yourself (with JDK 1.2 or 1.3).
  • Adobe Acrobat Reader from Adobe Systems Incorporated.
     

Getting started with iText

 There are three pages that are extremely important if you want to work with iText.
 

  1. The first is the tutorial. Not all functionality available in iText is explained, but it's a good place to start. If you click on one of the features in the overview, you get some explanation and some examples on how to use these features. There's also the Javadoc pages for more detail on every method (again: not every method is documented, but we're working on it).
  2. If the examples don't work or you experience some typical newbie problems, please consult the Frequently Asked Questions page.
  3. If you need something that isn't on the feature list, please check the mailing-list archives. Lots of features are yet to be documented, but most of the iText functionality has been commented in the mailing-list. If you have a problem that has not been dealt with yet (or that should be in the FAQ), you can post it to the mailing-list. But it's always a good idea to check archives first.

License Agreement

 iText is published under 2 different licenses: MPL and LGPL.

If you are a new user of iText, MPL is recommended (without the LGPL). MPL is less strict than LGPL. Please read the MPL license agreement before downloading and/or using iText.
LGPL is maintained for backwarts compatibility only. If you choose the LGPL, you need to mention the MPL as an alternative license. Please read the LGPL license agreement for more info.

This library is free and I want it to stay free: you can use it without paying a fee; you don't need to register anywhere. Only keep in mind that agreeing with the license is crucial to protect the software, its developers and its users. Please read section 15 and 16 of the LGPLicense with special attention: This library is distributed in the hope that it will be useful, but WITHOUT any warranty. If you don't like free software, don't (ab)use it!

Some companies have a policy not to use Free / Open Source Software without a license or a support contract. The iText developers can't and won't sell you such a contract, but they have granted Leonard Rosenthol and his company PDF Sages the right to sell licenses and support contracts on a case per case basis. There was no money involved in this deal; the developers of iText are not on the paylist of PDF Sages. The responsibility for these contracts lies with PDF Sages, not with the developers Paulo Soares and/or Bruno Lowagie.

Compiling the source

The iText jar is compiled with the JDK1.4. If you are using an older JVM in your environment, you could experience some compatibility problems. In this case it is better NOT to use the downloaded jar, but to compile the code yourself with your own JDK. If you have a version older than the JDK1.2, you will have to download an adapted version of the source code from the Early Access site, as well as the 'Collection' classes from SUN. If you are using the JDK 1.2 or 1.3, you will probably need some extra J2EE jar for the packages com.lowagie.text.xml and com.lowagie.text.html. If you don't need the XML/HTML stuff, you can delete those packages.
There are of course also some ANT scripts that will make getting and compiling the source a lot easier. There is a separate page on iText ANT scripts.

Example: Generates a simple 'Hello World' PDF file

/*
 * $Id: HelloWorld.java,v 1.6 2005/05/09 11:52:44 blowagie Exp $
 * $Name:  $
 *
 * This code is part of the 'iText Tutorial'.
 * You can find the complete tutorial at the following address:
 * http://itextdocs.lowagie.com/tutorial/
 *
 * This code is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * itext-questions@lists.sourceforge.net
 */

package com.lowagie.examples.general;

import java.io.FileOutputStream;
import java.io.IOException;

import com.lowagie.text.*;
import com.lowagie.text.pdf.PdfWriter;

/**
 * Generates a simple 'Hello World' PDF file.
 * 
 * @author blowagie
 */

public class HelloWorld {

	/**
	 * Generates a PDF file with the text 'Hello World'
	 * 
	 * @param args no arguments needed here
	 */
	public static void main(String[] args) {

		System.out.println("Hello World");

		// step 1: creation of a document-object
		Document document = new Document();
		try {
			// step 2:
			// we create a writer that listens to the document
			// and directs a PDF-stream to a file
			PdfWriter.getInstance(document,
					new FileOutputStream("HelloWorld.pdf"));

			// step 3: we open the document
			document.open();
			// step 4: we add a paragraph to the document
			document.add(new Paragraph("Hello World"));
		} catch (DocumentException de) {
			System.err.println(de.getMessage());
		} catch (IOException ioe) {
			System.err.println(ioe.getMessage());
		}

		// step 5: we close the document
		document.close();
	}
}

 

Rating Not Rated
Votes 0

Popularity 5/5: Very Popular
Downloads 1588
Page Views 14918

Download Now!


Home Code Examples Java Forum All Java Tips Books Submit News, Code... Search... Offshore Software Tech Doodling

RSS feed Java FAQ RSS feed Java FAQ News     

    RSS feed Java Forums RSS feed Java Forums

All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest 1999-2006 by Java FAQs Daily Tips.

Interactive software released under GNU GPL, Code Credits, Privacy Policy