Sophie

Sophie

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

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: Generating HTML with iText</title><meta name="Description" content="How-to generate a HTML documents with iText"><meta name="Keywords" content="HTML, 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>Generating HTML with iText</h2><div id="content"><div id="sidebar"><a class="toc" href="./../index.html#html">
							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="#reason">Why I wrote HtmlWriter.</a></li><li><a href="#helloworld">The Hello World example for HTML</a></li><li><a href="#metadata">Metadata in HTML</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/html/HelloHtml.java">HelloHtml</a><br><div class="description">Generates a simple 'Hello World' HTML file</div><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/html/HelloWorld.html">HelloWorld.html</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/html/HelloWorldMeta.java">HelloWorldMeta</a><br><div class="description">Generates an HTML file with metadata</div><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/html/HelloWorldMeta.html">HelloWorldMeta.html</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/html/JavaScriptAction.java">JavaScriptAction</a><br><div class="description">Generates an HTML file with JavaScript</div><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/html/JavaScriptAction.html">JavaScriptAction.html</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/html/Images.java">Images</a><br><div class="description">Adds different formats of images to a document.</div><div class="small">Input:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/html/otsoe.jpg">otsoe.jpg</a></li><li><a href="http://itext.ugent.be/library/com/lowagie/examples/html/iText.bmp">iText.bmp</a></li><li><a href="http://itext.ugent.be/library/com/lowagie/examples/html/pngnow.png">pngnow.png</a></li><li><a href="http://itext.ugent.be/library/com/lowagie/examples/html/iText.tif">iText.tif</a></li><li><a href="http://itext.ugent.be/library/com/lowagie/examples/html/getacro.gif">getacro.gif</a></li><li><a href="http://itext.ugent.be/library/com/lowagie/examples/html/iText.wmf">iText.wmf</a></li></ul><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/html/images_wrong.html">images_wrong.html</a></li><li><a href="http://itext.ugent.be/library/com/lowagie/examples/html/images_right.html">images_right.html</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/html/ImagesURL.java">ImagesURL</a><br><div class="description">Adds images to an HTML file using the complete URL.</div><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/html/images_wrong.html">images_wrong.html</a></li><li><a href="http://itext.ugent.be/library/com/lowagie/examples/html/images.html">images.html</a></li></ul></div><div class="example"><div class="small">ANT script (all examples):</div><ul><li><a href="./../html/build.xml">
					build.xml
				</a></li></ul></div></div><div id="main"><font color="#FF0000" size="+2">UNDER CONSTRUCTION</font><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=14">
				Chapter 14:
			</a>Automating PDF creation</li></ul></p>
		</div><a class="top" href="#top">Go to top of the page</a><a name="reason"></a><div class="title">Why I wrote HtmlWriter.:</div><div xmlns="http://www.w3.org/1999/xhtml">
iText wasn't always called iText. The first name of the library was 'rugPdf'.
RUG was the abbreviation for Rijksuniversiteit Gent (my employer since november 1998).
Writing iText was one of my first tasks at the University.
The new abbreviation is <a href="http://www.ugent.be">UGent</a> because the
'Rijks' was droppend and Ghent University is now called 'Universiteit Gent'
in Dutch (or rather: in Flemish, because Ghent is a Belgian City).<br>
The very first versions of this rugPdf library were very low level
and meant to generate PDF only:
you had to know a lot about the PDF syntax to be able to use it.
In order to make PDF generation more transparant (and to avoid that our
developers should all be PDF experts), I rewrote rugPdf completely after
our initial product were successfully brought into production.
I created a plethora of high level objects, such as
<a xmlns="" href="http://itext.ugent.be/library/src/com/lowagie/text/Document.java">com.lowagie.text.Document</a>,
<a href="http://itext.ugent.be/library/src/com/lowagie/text/Chunk.java">com.lowagie.text.Chunk</a>,
<a href="http://itext.ugent.be/library/src/com/lowagie/text/Phrase.java">com.lowagie.text.Phrase</a>,
<a href="http://itext.ugent.be/library/src/com/lowagie/text/Paragraph.java">com.lowagie.text.Paragraph</a>,
<a href="http://itext.ugent.be/library/src/com/lowagie/text/List.java">com.lowagie.text.List</a>,...<br xmlns="http://www.w3.org/1999/xhtml">
These objects would be translated to PDF behind the screens:
developers would no longer need to know anything about PDF syntax.
However: for me it was very hard to debug the source code.
While testing, lots of broken PDF files were generated and
it wasn't always possible to retrieve the exact location where
everything went wrong: just try reading half of a generated PDF
file in a plain text editor and you will know why ;-)<br>
So I had the idea to have two Writers listening to one document
at the same time: <a xmlns="" href="http://itext.ugent.be/library/src/com/lowagie/text/pdf/PdfWriter.java">com.lowagie.text.pdf.PdfWriter</a>
and <a href="http://itext.ugent.be/library/src/com/lowagie/text/html/HtmlWriter.java">com.lowagie.text.html.HtmlWriter</a>.
As the HTML format is less critical than PDF syntax,
it was sufficient for me to take one look at the broken HTML file
to see what high level object caused the Runtime error.<br xmlns="http://www.w3.org/1999/xhtml">
<br>
The moral of this long introduction is:
<a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/html/HtmlWriter.html">HtmlWriter</a>
is a class that produces HTML, but it was only written for debugging reasons.
If you are looking for a library that generates HTML, you will find other
products with far more features and possibilities than provided with iText.
If you want to generate documents in different formats simultaneously,
than you might find <a href="http://itext.ugent.be/library/api/com/lowagie/text/html/HtmlWriter.html">HtmlWriter</a>
useful.
</div><a class="top" href="#top">Go to top of the page</a><a name="helloworld"></a><div class="title">The Hello World example for HTML:</div><div xmlns="http://www.w3.org/1999/xhtml">
We take the first example we made in <a xmlns="" href="./../general/index.html#5steps">PDF</a>
and <a href="./../rtf/index.html#rtfdocument">RTF</a> and now we let the document
listen to <a href="http://itext.ugent.be/library/src/com/lowagie/text/html/HtmlWriter.java">com.lowagie.text.html.HtmlWriter</a>:
<div id="example">
					Example: java
					<a href="http://itext.ugent.be/library/com/lowagie/examples/html/HelloHtml.java">
						com.lowagie.examples.html.HelloHtml</a><br>Generates a simple 'Hello World' HTML file: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/html/HelloWorld.html">HelloWorld.html</a><br></div>
</div><a class="top" href="#top">Go to top of the page</a><a name="metadata"></a><div class="title">Metadata in HTML:</div><div xmlns="http://www.w3.org/1999/xhtml">
As described in the section on <a xmlns="" href="./../general/index.html#step3">adding metadata before opening a document</a>,
there are specific methods to add the title, author, subject and keywords of the document contents.
These methods will add the specific META-tags to your HTML. The methods to add the creator, producer
and creationdate, will add comment sections to the HTML-header. You can use
<a href="http://itext.ugent.be/library/api/com/lowagie/text/Document.html#addHeader(java.lang.String,%20java.lang.String)">addHeader(java.lang.String,%20java.lang.String)</a>
to add other META tags (such as 'Expires').
<pre xmlns="http://www.w3.org/1999/xhtml" class="commandline">// standard meta information
document.addTitle("Hello World example");
document.addAuthor("Bruno Lowagie");
document.addSubject("This example explains step 3 in Chapter 1");
document.addKeywords("Metadata, iText, step 3, tutorial");
// custom (HTML) meta information
document.addHeader("Expires", "0");
// meta information that will be in a comment section in HTML
document.addCreator("My program using iText");</pre>
This is what the HTML header will look like:
<pre class="commandline">&lt;head&gt;
	&lt;title&gt;
		Hello World example
	&lt;/title&gt;
	&lt;meta name="author" content="Bruno Lowagie" /&gt;
	&lt;meta name="subject" content="This example explains step 3 in Chapter 1" /&gt;
	&lt;meta name="keywords" content="Metadata, iText, step 3, tutorial" /&gt;
	&lt;meta name="Expires" content="0" /&gt;
	&lt;!-- Creator: My program using iText --&gt;
	&lt;!-- Producer: iTextXML by lowagie.com --&gt;
	&lt;!-- CreationDate: Fri Dec 17 14:13:18 CET 2004 --&gt;
&lt;/head&gt;</pre>
<div id="example">
					Example: java
					<a xmlns="" href="http://itext.ugent.be/library/com/lowagie/examples/html/HelloWorldMeta.java">
						com.lowagie.examples.html.HelloWorldMeta</a><br>Generates an HTML file with metadata: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/html/HelloWorldMeta.html">HelloWorldMeta.html</a><br></div>
</div><a class="top" href="#top">Go to top of the page</a><div id="footer" xmlns="http://www.w3.org/1999/xhtml">
			Page Updated: 2006/09/17 10:13:51
			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=0321130073&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/0321130073/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=007222942X&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/007222942X/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=HTML&=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>