Sophie

Sophie

distrib > Mandriva > 2008.1 > i586 > by-pkgid > 927a1532fb070c51449654bb68b5bde2 > files > 389

itext-manual-2.0.8-0.0.2mdv2008.1.i586.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><META http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>iText Tutorial: Hello World</title><meta name="Description" content="How-to generate a PDF document with iText in 5 easy steps."><meta name="Keywords" content="PDF, JAVA, iText, examples, Lowagie, Bruno"><link rel="stylesheet" href="./../style.css" type="text/css"></head><body><a name="top" class="logo" href="http://www.lowagie.com/iText"><img src="http://www.lowagie.com/iText/images/logo.gif" border="0" alt="iText"></a><h1>Tutorial: iText by Example</h1><h2>Hello World</h2><div id="content"><div id="sidebar"><a class="toc" href="./../index.html#general">
							Table of Contents
						</a><div align="Center" class="small">Best viewed with:<br><script type="text/javascript"><!--
google_ad_client = "pub-0340380473790570";
google_ad_width = 180;
google_ad_height = 60;
google_ad_format = "180x60_as_rimg";
google_cpa_choice = "CAAQyaj8zwEaCIwcWMzeycafKMu293M";
//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script></div><div class="sidetitle">Sections:</div><ul><li><a href="#inaction">In the book</a></li><li><a href="#5steps">Creating a document in 5 steps.</a></li><li><a href="#step1">step 1: the Document object</a></li><li><a href="#step2">step 2: the Writer object</a></li><li><a href="#step3">step 3: opening the document</a></li><li><a href="#step4">step 4: adding content</a></li><li><a href="#step5">step 5: closing the document</a></li></ul><br><br><div class="sidetitle">Examples:</div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/general/HelloWorld.java">HelloWorld</a><br><div class="description">Generates a simple 'Hello World' PDF file</div><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/general/HelloWorld.pdf">HelloWorld.pdf</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/general/DefaultPageSize.java">DefaultPageSize</a><br><div class="description">Generates a PDF document with the default page size and some other predefined standard pagesizes</div><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/general/DefaultPageSize.pdf">DefaultPageSize.pdf</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/general/LandscapePortrait.java">LandscapePortrait</a><br><div class="description">Generates a PDF document with the first page in Lanscape; the second page in Portrait</div><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/general/LandscapePortrait.pdf">LandscapePortrait.pdf</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/general/CustomPageSize.java">CustomPageSize</a><br><div class="description">Generates a PDF document with a custom pagesize and backgroundcolor</div><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/general/CustomPageSize.pdf">CustomPageSize.pdf</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/general/Margins.java">Margins</a><br><div class="description">Demonstrates the margin functionality</div><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/general/Margins.pdf">Margins.pdf</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/general/HelloSystemOut.java">HelloSystemOut</a><br><div class="description">Writes PDF output to System.out</div><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/general/HelloWorld.txt">HelloWorld.txt</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/general/HelloWorldMultiple.java">HelloWorldMultiple</a><br><div class="description">Writing to different writers at the same time; using pause() and resume()</div><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/general/HelloWorldPdf.pdf">HelloWorldPdf.pdf</a></li><li><a href="http://itext.ugent.be/library/com/lowagie/examples/general/HelloWorldRtf.rtf">HelloWorldRtf.rtf</a></li><li><a href="http://itext.ugent.be/library/com/lowagie/examples/general/HelloWorldHtml.html">HelloWorldHtml.html</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/general/HelloEncrypted.java">HelloEncrypted</a><br><div class="description">Again a PDF with the text 'Hello World', but this time the document is encrypted. To read it, you need to know the userpassword: 'Hello'</div><div class="small">Extra jars needed:</div><ul><li>bcprov-jdk14-135.jar</li></ul><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/general/HelloEncrypted.pdf">HelloEncrypted.pdf</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/general/HelloWorldMeta.java">HelloWorldMeta</a><br><div class="description">Adding metadata to a new PDF document</div><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/general/HelloWorldMeta.pdf">HelloWorldMeta.pdf</a></li></ul></div><div class="example"><div class="small">ANT script (all examples):</div><ul><li><a href="./../general/build.xml">
					build.xml
				</a></li></ul></div></div><div id="main"><a name="inaction"></a><div class="title">In the book:</div><div xmlns="http://www.w3.org/1999/xhtml" xmlns:site="http://www.lowagie.com/iText/site">
		<p xmlns=""><a href="http://itext.ugent.be/itext-in-action/"><img src="http://itext.ugent.be/img/lowagie_3d.jpg" border="0" align="right"></a>
			The examples in this free online tutorial will help you getting started
			with iText. Note that most examples are two years old.
			Some of the examples may be obsolete. Also the theory that
			comes with the examples isn't always 100% accurate.
			If you want more recent examples or if you want to know more
			about the theoretical background of	PDF and iText, please consult the book
			<a href="http://itext.ugent.be/itext-in-action/">
				"iText in Action".
			</a>
			Note that the first and the third chapter of the book
			can be downloaded for free from <a href="http://www.manning.com/affiliate/idevaffiliate.php?id=223_53">http://manning.com/lowagie/</a></p><p>
			More specifically:
			<ul><li><a class="subtitle" href="http://itext.ugent.be/itext-in-action/chapter.php?chapter=2">
				Chapter 2:
			</a>PDF engine jump-start</li><li><a class="subtitle" href="http://itext.ugent.be/itext-in-action/chapter.php?chapter=3">
				Chapter 3:
			</a>PDF, why and when</li></ul></p>
		</div><a class="top" href="#top">Go to top of the page</a><a name="5steps"></a><div class="title">Creating a document in 5 steps.:</div><div xmlns="http://www.w3.org/1999/xhtml">
When I learned my first programming language (some old BASIC dialect
on a <a href="http://www.99er.net/">TI-99/4A Home Compiter</a>),
one of the first programs I made was a 'Hello World' example.
The year was 1982, my age: 12. Now, more than 20 years later,
I am still writing the same program: a standalone example that
prints 'Hello World', this time not on the cyan colored Texas Instruments screen,
but in a PDF document file.<br>
This example shows you the 5 basic steps you have to take for every
new PDF document you are creating from scratch with iText:
<ul>
<li><b>Step 1:</b> Create an <a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/Document.html#constructor_summary">instance</a> of <a href="http://itext.ugent.be/library/src/com/lowagie/text/Document.java">com.lowagie.text.Document</a>:
<div xmlns="http://www.w3.org/1999/xhtml" class="commandline"></div>Document document = new Document();</li>
<li><b>Step 2:</b> Create a Writer (for instance <a xmlns="" href="http://itext.ugent.be/library/src/com/lowagie/text/pdf/PdfWriter.java">com.lowagie.text.pdf.PdfWriter</a>) that listens to this document and writes the document to the OutputStream of your choice:
<div xmlns="http://www.w3.org/1999/xhtml" class="commandline">PdfWriter.getInstance(document, new FileOutputStream("HelloWorld.pdf"));</div></li>
<li><b>Step 3:</b> Open the document:
<div class="commandline">document.open();</div></li>
<li><b>Step 4:</b> Add content to the document:
<div class="commandline">document.add(new Paragraph("Hello World"));</div></li>
<li><b>Step 5:</b> Closes the document:
<div class="commandline">document.close();</div></li>
</ul>
<div id="example">
					Example: java
					<a xmlns="" href="http://itext.ugent.be/library/com/lowagie/examples/general/HelloWorld.java">
						com.lowagie.examples.general.HelloWorld</a><br>Generates a simple 'Hello World' PDF file: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/general/HelloWorld.pdf">HelloWorld.pdf</a><br></div>
In the following sections, we will take a closer look into each step.
</div><a class="top" href="#top">Go to top of the page</a><a name="step1"></a><div class="title">step 1: the Document object:</div><div xmlns="http://www.w3.org/1999/xhtml">
Class <a xmlns="" href="http://itext.ugent.be/library/src/com/lowagie/text/Document.java">com.lowagie.text.Document</a> has <a href="http://itext.ugent.be/library/api/com/lowagie/text/Document.html#constructor_summary">3 constructors</a>:
<pre xmlns="http://www.w3.org/1999/xhtml" class="commandline">public Document();
public Document(Rectangle pageSize);
public Document(Rectangle pageSize,
   int marginLeft,
   int marginRight,
   int marginTop,
   int marginBottom);</pre>
The first constructor calls the second one, with <a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/PageSize.html#A4">PageSize.A4</a> as parameter.
The second constructor calls the third one, with 36 as value for each margin.<br xmlns="http://www.w3.org/1999/xhtml"><br>
<div class="subtitle">Pagesize</div>
The default PageSize is DIN A4 (iText is a European library; A4 is the most common format overhere),
but for your convenience class <a xmlns="" href="http://itext.ugent.be/library/src/com/lowagie/text/PageSize.java">com.lowagie.text.PageSize</a> offers you a very complete list of standard PageSizes:
A0-A10, LEGAL, LETTER, HALFLETTER, _11x17, LEDGER, NOTE, B0-B5, ARCH_A-ARCH_E, FLSA and FLSE.
<div id="example">
					Example: java
					<a href="http://itext.ugent.be/library/com/lowagie/examples/general/DefaultPageSize.java">
						com.lowagie.examples.general.DefaultPageSize</a><br>Generates a PDF document with the default page size and some other predefined standard pagesizes: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/general/DefaultPageSize.pdf">DefaultPageSize.pdf</a><br></div>
Most these standard pageSizes are in PORTRAIT-format.
To create a document in landscape format, just make the height smaller than the width.
With the standard pagesizes all you have to do is <a href="http://itext.ugent.be/library/api/com/lowagie/text/Rectangle.html#rotate()">rotate()</a> the Rectangle:
<div xmlns="http://www.w3.org/1999/xhtml" class="commandline">Document document = new Document(PageSize.A4.rotate());</div>
<div id="example">
					Example: java
					<a xmlns="" href="http://itext.ugent.be/library/com/lowagie/examples/general/LandscapePortrait.java">
						com.lowagie.examples.general.LandscapePortrait</a><br>Generates a PDF document with the first page in Lanscape; the second page in Portrait: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/general/LandscapePortrait.pdf">LandscapePortrait.pdf</a><br></div>
Of course you aren't limited to this list. You can create pages of any size you want.
(Although there is a maximum of 200 by 200 inches; 45 by 45 inches for Acrobat 3.0 compatibility).
With the PageSize, there is also the possibility to define a backgroundcolor.
In the following example, we create a long, narrow document with a yellowish backgroundcolor:
<div id="example">
					Example: java
					<a href="http://itext.ugent.be/library/com/lowagie/examples/general/CustomPageSize.java">
						com.lowagie.examples.general.CustomPageSize</a><br>Generates a PDF document with a custom pagesize and backgroundcolor: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/general/CustomPageSize.pdf">CustomPageSize.pdf</a><br></div>
If you want to know more about the measurement unit, see the <a href="./../general/faq/index.html#measurements">FAQ</a>.<br xmlns="http://www.w3.org/1999/xhtml"><br>
<div class="subtitle">Margins</div>
In step 4, you will be adding content to the document. If you use high level objects,
you needn't worry about margins and page layout. The high level objects take care of that
for you. Of course you will have to define the margins first. That is: if you want other
margins than the standard 36 points (half an inch).<br>
You can also change the margins while you are adding content. Note that the changes
will only be noticed on the NEXT page. If you want the margins mirrored (odd and even pages),
you can do this with this method: <a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/Document.html#setMarginMirroring(boolean)">setMarginMirroring(true)</a>.
<div id="example">
					Example: java
					<a href="http://itext.ugent.be/library/com/lowagie/examples/general/Margins.java">
						com.lowagie.examples.general.Margins</a><br>Demonstrates the margin functionality: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/general/Margins.pdf">Margins.pdf</a><br></div>
If you want to know more about the measurement unit, see the <a href="./../general/faq/index.html#measurements">FAQ</a>.<br xmlns="http://www.w3.org/1999/xhtml"><br>
<div class="subtitle">Why getPagenumber doesn't work.</div>
Class Document is all about content, not about presentation.
Different writers can listen to the same Document object,
so it makes absolutely no sense asking the Document object for its current pagenumber.
Which number would the Document have to return? The pagenumber of the PDF representation
or the one of the HTML (this makes even less sense)? In short: you should ask the specific writer
for the pagenumber, NOT the Document object.
</div><a class="top" href="#top">Go to top of the page</a><a xmlns="" name="step2"></a><div class="title">step 2: the Writer object:</div><div xmlns="http://www.w3.org/1999/xhtml">
Once our <a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/Document.html">Document</a> is created,
we can create one or more instances of writers that listen to this document.
All writers should be derived from the abstract class <a href="http://itext.ugent.be/library/src/com/lowagie/text/DocWriter.java">com.lowagie.text.DocWriter</a>.
For the moment there are three kinds of writers supported:
<dl xmlns="http://www.w3.org/1999/xhtml">
<dt><a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/pdf/PdfWriter.html#getInstance(com.lowagie.text.Document,%20java.io.OutputStream)">PdfWriter</a></dt>
<dd xmlns="http://www.w3.org/1999/xhtml">Generates documents in the Portable Document Format</dd>
<dt><a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/rtf/RtfWriter2.html#getInstance(com.lowagie.text.Document,%20java.io.OutputStream)">RtfWriter</a></dt>
<dd xmlns="http://www.w3.org/1999/xhtml">Generates documents in RTF. Read more about this in the chapter '<a xmlns="" href="./../rtf/index.html#">RTF</a>'</dd>
<dt xmlns="http://www.w3.org/1999/xhtml"><a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/html/HtmlWriter.html#getInstance(com.lowagie.text.Document,%20java.io.OutputStream)">HtmlWriter</a></dt>
<dd xmlns="http://www.w3.org/1999/xhtml">Generates documents in HTML. This writer was initially written for debugging purposes (see <a xmlns="" href="./../html/index.html#">Generating HTML with iText</a>).</dd>
</dl>
All these Writers are derived from the abstract class <a href="http://itext.ugent.be/library/api/com/lowagie/text/DocWriter.html">DocWriter</a>.
The constructors of the writer-classes are protected. You can only create an instance with a static method:
<a href="http://itext.ugent.be/library/api/com/lowagie/text/pdf/PdfWriter.html#getInstance(com.lowagie.text.Document,%20java.io.OutputStream)">PdfWriter.getInstance</a>,
<a href="http://itext.ugent.be/library/api/com/lowagie/text/rtf/RtfWriter2.html#getInstance(com.lowagie.text.Document,%20java.io.OutputStream)">RtfWriter2.getInstance</a>
or <a href="http://itext.ugent.be/library/api/com/lowagie/text/html/HtmlWriter.html#getInstance(com.lowagie.text.Document,%20java.io.OutputStream)">HtmlWriter.getInstance</a>:
<div xmlns="http://www.w3.org/1999/xhtml" class="commandline">public static xxxWriter getInstance(Document document, OutputStream os) throws DocumentException</div>
(xxx being Pdf, Rtf or Html). For instance:
<div class="commandline">PdfWriter.getInstance(document, new FileOutputStream("HelloWorld.pdf"));</div>
It may surprise you that there seems to be 'no object'. You probably expect something like this:
<div class="commandline">PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("HelloWorld.pdf"));</div>
Actually there IS a writer object in both cases, but in simple applications you will never need it.<br>
<br>
The first parameter of the getInstance method is the <a xmlns="" href="http://itext.ugent.be/library/src/com/lowagie/text/Document.java">com.lowagie.text.Document</a> object
created in <a xmlns="http://www.w3.org/1999/xhtml" href="#step1">step 1</a>. The second parameter can be any java.io.OutputStream object.
In this tutorial we always use a java.io.FileOutputStream, but you can also use
a java.io.ByteArrayOutputStream to create PDF files in memory or a javax.servlet.ServletOutputStream
(see <a xmlns="" href="./../general/webapp/index.html#">iText in a Web Application</a>).
You can even write output to System.out if you want to (but it's not very nice to look at):<br xmlns="http://www.w3.org/1999/xhtml">
<img xmlns="" border="0" src="./../images/systemout.gif" alt="DOSBOX System.out"><br xmlns="http://www.w3.org/1999/xhtml">
<div id="example">
					Example: java
					<a xmlns="" href="http://itext.ugent.be/library/com/lowagie/examples/general/HelloSystemOut.java">
						com.lowagie.examples.general.HelloSystemOut</a><br>Writes PDF output to System.out: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/general/HelloWorld.txt">HelloWorld.txt</a><br></div>
Remark that you can have different writers listening to the same document at the same time.
For instance: if you want to sent a PDF to a browser directly from a servlet, but keep a copy
of the PDF in a file on the server, you could invoke getInstance twice with the same document-object,
but a different output stream.<br xmlns="http://www.w3.org/1999/xhtml">
At Ghent University, we write sheets with information on Study Programmes for the Course Catalogue
in 2 versions: one in HTML for the website and one in PDF for printing. This is done simultaneously
using the same source code, even using the same document object. The only difference is that at some
point, we pause the PdfWriter and we add a link from the HTML page to the PDF document. This is
demonstrated in the next example:
<div id="example">
					Example: java
					<a xmlns="" href="http://itext.ugent.be/library/com/lowagie/examples/general/HelloWorldMultiple.java">
						com.lowagie.examples.general.HelloWorldMultiple</a><br>Writing to different writers at the same time; using pause() and resume(): see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/general/HelloWorldPdf.pdf">HelloWorldPdf.pdf</a> <a href="http://itext.ugent.be/library/com/lowagie/examples/general/HelloWorldRtf.rtf">HelloWorldRtf.rtf</a> <a href="http://itext.ugent.be/library/com/lowagie/examples/general/HelloWorldHtml.html">HelloWorldHtml.html</a><br></div>
		</div><a class="top" href="#top">Go to top of the page</a><a name="step3"></a><div class="title">step 3: opening the document:</div><div xmlns="http://www.w3.org/1999/xhtml">
It is important to call <a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/Document.html#open()">Document.open()</a>.
iText will throw an exception if you try adding content before the document is open.
This is a design choice. There are several initialisations that should be done BEFORE you open
a Document. Most of them will be covered elsewhere in this tutorial.
We have a quick glance at two of them now:<br xmlns="http://www.w3.org/1999/xhtml"><br>
<div class="subtitle">Simple encryption</div>
if you want to generate an encrypted document, you should call
<a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/pdf/PdfWriter.html#setEncryption(boolean,%20java.lang.String,%20java.lang.String,%20int)">setEncryption</a>
BEFORE opening the Document-object. If you try setting the encryption after Document.open(),
a <a href="http://itext.ugent.be/library/api/com/lowagie/text/DocumentException.html">DocumentException</a>
will be thrown with the message <span xmlns="http://www.w3.org/1999/xhtml" class="commandline">Encryption can only be added before opening the document</span>.
<div id="example">
					Example: java
					<a xmlns="" href="http://itext.ugent.be/library/com/lowagie/examples/general/HelloEncrypted.java">
						com.lowagie.examples.general.HelloEncrypted</a><br>Again a PDF with the text 'Hello World', but this time the document is encrypted. To read it, you need to know the userpassword: 'Hello': see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/general/HelloEncrypted.pdf">HelloEncrypted.pdf</a><br>
						Extra jars needed in your CLASSPATH:
						 bcprov-jdk14-135.jar<br></div>
<div xmlns="http://www.w3.org/1999/xhtml" class="subtitle">metadata</div>
if we look at the Document Properties in Acrobat (under File in the menu),
we see that several fields are empty by default:<br>
<img xmlns="" border="0" src="./../images/metadata.gif" alt="HelloWorld without metadata"><br xmlns="http://www.w3.org/1999/xhtml">
<br>
Only two metadata methods are called by default:
<a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/Document.html#addProducer()">addProducer()</a>
and
<a href="http://itext.ugent.be/library/api/com/lowagie/text/Document.html#addCreationDate()">addCreationDate()</a>.
It's possible to change the producer and creation date, but you shouldn't.<br xmlns="http://www.w3.org/1999/xhtml">
We'll only document the methods to change the rest of the metadata in the
'Description' area:<br>
<table border="1" cellpadding="3">
<tr><td>Title:</td><td><a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/Document.html#addTitle(java.lang.String)">addTitle(java.lang.String)</a></td></tr>
<tr xmlns="http://www.w3.org/1999/xhtml"><td>Author:</td><td><a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/Document.html#addAuthor(java.lang.String)">addAuthor(java.lang.String)</a></td></tr>
<tr xmlns="http://www.w3.org/1999/xhtml"><td>Subject:</td><td><a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/Document.html#addSubject(java.lang.String)">addSubject(java.lang.String)</a></td></tr>
<tr xmlns="http://www.w3.org/1999/xhtml"><td>Keywords:</td><td><a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/Document.html#addKeywords(java.lang.String)">addKeywords(java.lang.String)</a></td></tr>
<tr xmlns="http://www.w3.org/1999/xhtml"><td>Application:</td><td><a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/Document.html#addCreator(java.lang.String)">addCreator(java.lang.String)</a></td></tr>
</table><br xmlns="http://www.w3.org/1999/xhtml">
This is a small code sample:
<pre class="commandline">document.addTitle("Hello World example");
document.addAuthor("Bruno Lowagie");
document.addSubject("This example explains how to add metadata.");
document.addKeywords("iText, Hello World, step 3, metadata");
document.addCreator("My program using iText");
</pre>
Compare the result on this screenshot:<br>
<img xmlns="" border="0" src="./../images/meta.gif" alt="HelloWorld with metadata"><br xmlns="http://www.w3.org/1999/xhtml">
<div id="example">
					Example: java
					<a xmlns="" href="http://itext.ugent.be/library/com/lowagie/examples/general/HelloWorldMeta.java">
						com.lowagie.examples.general.HelloWorldMeta</a><br>Adding metadata to a new PDF document: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/general/HelloWorldMeta.pdf">HelloWorldMeta.pdf</a><br></div>
If you study the API, you will see there is also a generic method
<a href="http://itext.ugent.be/library/api/com/lowagie/text/Document.html#addHeader(java.lang.String,%20java.lang.String)">addHeader(java.lang.String, java.lang.String)</a>.
That method has no effect on PdfWriter, but you can use it with
<a href="./../html/index.html#metadata">HtmlWriter</a>.
		</div><a class="top" href="#top">Go to top of the page</a><a name="step4"></a><div class="title">step 4: adding content:</div><div xmlns="http://www.w3.org/1999/xhtml">
There are different ways to add content to a PDF file.
The easiest way is to use <a xmlns="" href="./../index.html#part2">high level objects</a>
such as Chunk, Phrase, Paragraph,...
It is very important to realize that not all types of these objects are supported
in all types of writers. For instance:  the PdfPTable-object
is only supported in PDF, not in RTF or HTML. If you add a PdfPTable
to a Document, the listening RtfWriters or HtmlWriters
will ignore this.<br xmlns="http://www.w3.org/1999/xhtml">
If you don't need RTF or HTML, you can also add content at
<a xmlns="" href="./../index.html#part4">absolute positions</a>.
A lot of the standard PDF syntax is supported in iText, so you can do some
very powerful things with the library.<br xmlns="http://www.w3.org/1999/xhtml">
Adding content using the PdfGraphics2D-object
(extends <a href="http://java.sun.com/j2se/1.3/docs/api/java/awt/Graphics2D.html">java.awt.Graphics2D</a>) is
also possible. You can read more about this elsewhere in the tutorial.
		</div><a class="top" href="#top">Go to top of the page</a><a xmlns="" name="step5"></a><div class="title">step 5: closing the document:</div><div xmlns="http://www.w3.org/1999/xhtml">
 Closing the document is very important, because it flushes and closes the outputstream to which the writer is writing. The close-method is called in the finalize-method, but you shouldn't count on that. You should always close the document yourself!
		</div><a class="top" href="#top">Go to top of the page</a><div id="footer">
			Page Updated: 2007/01/26 14:41:44
			Copyright &copy; 1999-2005
			Bruno Lowagie<br><a href="http://www.lowagie.com/iText/">iText</a> is a Free Java-Pdf library by Bruno Lowagie and Paulo Soares.
		</div></div></div><div class="commercial"><br><script type="text/javascript"><!--
google_ad_client = "pub-0340380473790570";
google_ad_width = 120;
google_ad_height = 600;
google_ad_format = "120x600_as";
google_ad_channel ="";
google_ad_type = "text_image";
google_color_border = "FFFFFF";
google_color_bg = "FFFFFF";
google_color_link = "1B09BD";
google_color_url = "100670";
google_color_text = "707070";
//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script><br><br><div class="subtitle">Amazon books:</div><script type="text/javascript"><!--
document.write('<iframe src="http://rcm.amazon.com/e/cm?t=itisacatalofwebp&o=1&p=8&l=as1&asins=1932394796&fc1=000000&lc1=0000ff&bc1=&lt1=_blank&IS2=1&bg1=ffffff&f=ifr" width="120" height="240" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" align="Center"></iframe>');
//--></script><a xmlns="" href="http://www.amazon.co.uk/exec/obidos/ASIN/1932394796/catloogjecom-21" class="amazonlinks">
			amazon.co.uk-link
		</a><br><br><script type="text/javascript"><!--
document.write('<iframe src="http://rcm.amazon.com/e/cm?t=itisacatalofwebp&o=1&p=8&l=as1&asins=3540608540&fc1=000000&lc1=0000ff&bc1=&lt1=_blank&IS2=1&bg1=ffffff&f=ifr" width="120" height="240" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" align="Center"></iframe>');
//--></script><a href="http://www.amazon.co.uk/exec/obidos/ASIN/3540608540/catloogjecom-21" class="amazonlinks">
			amazon.co.uk-link
		</a><br><br><script type="text/javascript"><!--
document.write('<iframe src="http://rcm.amazon.com/e/cm?t=itisacatalofwebp&o=1&p=8&l=as1&asins=0321304748&fc1=000000&lc1=0000ff&bc1=&lt1=_blank&IS2=1&bg1=ffffff&f=ifr" width="120" height="240" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" align="Center"></iframe>');
//--></script><a href="http://www.amazon.co.uk/exec/obidos/ASIN/0321304748/catloogjecom-21" class="amazonlinks">
			amazon.co.uk-link
		</a><br><br><script type="text/javascript"><!--
document.write('<iframe src="http://rcm.amazon.com/e/cm?t=itisacatalofwebp&o=1&p=8&l=as1&asins=0321305310&fc1=000000&lc1=0000ff&bc1=&lt1=_blank&IS2=1&bg1=ffffff&f=ifr" width="120" height="240" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" align="Center"></iframe>');
//--></script><a href="http://www.amazon.co.uk/exec/obidos/ASIN/0321305310/catloogjecom-21" class="amazonlinks">
			amazon.co.uk-link
		</a><br><br><script type="text/javascript"><!--
document.write('<iframe src="http://rcm.amazon.com/e/cm?t=itisacatalofwebp&o=1&p=10&l=st1&mode=books&search=JAVA&=1&fc1=&lc1=&lt1=&bg1=&f=ifr" width="120" height="460" border="0" frameborder="0" style="border:none;" scrolling="no" marginwidth="0" marginheight="0"></iframe>');
//--></script><br><script type="text/javascript"><!--
document.write('<iframe src="http://rcm.amazon.com/e/cm?t=itisacatalofwebp&o=1&p=10&l=st1&mode=books&search=PDF&=1&fc1=&lc1=&lt1=&bg1=&f=ifr" width="120" height="460" border="0" frameborder="0" style="border:none;" scrolling="no" marginwidth="0" marginheight="0"></iframe>');
//--></script><br></div></body></html>