Sophie

Sophie

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

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: Viewerpreferences, Pagelabels, Optional Content and Bookmarks</title><meta name="Description" content="Deals with all the PDF Viewerpreferences, Bookmarks, Outlines, Destinations,... functionality"><meta name="Keywords" content="PDF, JAVA, iText, examples, pagelabels, viewerpreferences, bookmarks, outlines, destinations, Chapter, Section, 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>Viewerpreferences, Pagelabels, Optional Content and Bookmarks</h2><div id="content"><div id="sidebar"><a class="toc" href="./../../index.html#objects_bookmarks">
							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="#viewerprefs">Viewerpreferences</a></li><li><a href="#pagelabels">Pagelabels</a></li><li><a href="#layers">Optional Content</a></li><li><a href="#bookmarks">Bookmarks</a></li><li><a href="#destinations">Creating Destinations</a></li><li><a href="#outlineactions">Outlines and Actions</a></li><li><a href="#chapter">the Chapter and Section object</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/objects/bookmarks/ViewerPreferences.java">ViewerPreferences</a><br><div class="description">Creates five versions of the same document, but with different viewerpreferences</div><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/TwoColumnLeft.pdf">TwoColumnLeft.pdf</a></li><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/HideMenuToolbar.pdf">HideMenuToolbar.pdf</a></li><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/FullScreen.pdf">FullScreen.pdf</a></li><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/WithTitle.pdf">WithTitle.pdf</a></li><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/NoScaling.pdf">NoScaling.pdf</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/PageLabels.java">PageLabels</a><br><div class="description">Creates a document with pagelabels</div><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/PageLabels.pdf">PageLabels.pdf</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/Layers.java">Layers</a><br><div class="description">Creates a document with text in different layers</div><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/Layers.pdf">Layers.pdf</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/Bookmarks.java">Bookmarks</a><br><div class="description">Creates a document with Bookmarks for every new Paragraph that is added</div><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/Bookmarks.pdf">Bookmarks.pdf</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/Destinations.java">Destinations</a><br><div class="description">Creates a document with destinations that can be called from Bookmarks</div><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/Destinations.pdf">Destinations.pdf</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/OutlineActions.java">OutlineActions</a><br><div class="description">Creates a document with external destinations or actions that can be called from Bookmarks</div><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/OutlineActions.pdf">OutlineActions.pdf</a></li><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/remote.pdf">remote.pdf</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/ChapterSection.java">ChapterSection</a><br><div class="description">Creates a document with Chapters and Sections (automatic outlines)</div><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/ChapterSection.pdf">ChapterSection.pdf</a></li></ul></div><div class="example"><a class="source" href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/HtmlIndex.java">HtmlIndex</a><br><div class="description">Creates an HTML index of a file that has bookmarks</div><div class="small">Output:</div><ul><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/ChapterSection_index.html">ChapterSection_index.html</a></li><li><a href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/OutlineActions_index.html">OutlineActions_index.html</a></li></ul></div><div class="example"><div class="small">ANT script (all examples):</div><ul><li><a href="./../../objects/bookmarks/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=4">
				Chapter 4:
			</a>Composing text elements</li><li><a class="subtitle" href="http://itext.ugent.be/itext-in-action/chapter.php?chapter=13">
				Chapter 13:
			</a>Browsing a PDF document</li><li><a class="subtitle" href="http://itext.ugent.be/itext-in-action/chapter.php?chapter=15">
				Chapter 15:
			</a>Creating annotations and fields</li></ul></p>
		</div><a class="top" href="#top">Go to top of the page</a><a name="viewerprefs"></a><div class="title">Viewerpreferences:</div><div xmlns="http://www.w3.org/1999/xhtml">
Every end user can change his viewerpreferences in Acrobat, but as producer of PDF documents,
you can add some viewerpreferences to the document. This can be done with the method
<a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/pdf/PdfWriter.html#setViewerPreferences(int)">setViewerPreferences()</a>.
The parameter can be composed by ORing some of the constants that are explained below:
<pre xmlns="http://www.w3.org/1999/xhtml" class="commandline">writer1.setViewerPreferences(PdfWriter.PageLayoutTwoColumnLeft);
writer2.setViewerPreferences(PdfWriter.HideMenubar
	| PdfWriter.HideToolbar);
writer3.setViewerPreferences(PdfWriter.PageLayoutTwoColumnRight
	| PdfWriter.PageModeFullScreen
	| PdfWriter.NonFullScreenPageModeUseThumbs);
writer4.setViewerPreferences(PdfWriter.DisplayDocTitle);</pre>
<div id="example">
					Example: java
					<a xmlns="" href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/ViewerPreferences.java">
						com.lowagie.examples.objects.bookmarks.ViewerPreferences</a><br>Creates five versions of the same document, but with different viewerpreferences: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/TwoColumnLeft.pdf">TwoColumnLeft.pdf</a> <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/HideMenuToolbar.pdf">HideMenuToolbar.pdf</a> <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/FullScreen.pdf">FullScreen.pdf</a> <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/WithTitle.pdf">WithTitle.pdf</a> <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/NoScaling.pdf">NoScaling.pdf</a><br></div>
This is the list with viewerpreferences that are supported in iText:
<ul xmlns="http://www.w3.org/1999/xhtml">
<li>The page layout to be used when the document is opened (choose one).
<ul>
<li><b>PageLayoutSinglePage</b> - Display one page at a time. (default)</li>
<li><b>PageLayoutOneColumn</b> - Display the pages in one column.</li>
<li><b>PageLayoutTwoColumnLeft</b> - Display the pages in two columns, with oddnumbered pages on the left.</li>
<li><b>PageLayoutTwoColumnRight</b> - Display the pages in two columns, with oddnumbered pages on the right.</li>
</ul>
</li>

<li>The page mode how the document should be displayed when opened (choose one).
<ul>
<li><b>PageModeUseNone</b> - Neither document outline nor thumbnail images visible. (default)</li>
<li><b>PageModeUseOutlines</b> - Document outline visible.</li>
<li><b>PageModeUseThumbs</b> - Thumbnail images visible.</li>
<li><b>PageModeFullScreen</b> - Full-screen mode, with no menu bar, window controls, or any other window visible.</li>
<li><b>PageModeUseOC</b> - Optional content group panel visible</li>
</ul>
</li>

<li><b>HideToolbar</b> - A flag specifying whether to hide the viewer application's tool bars when the document is active.</li>
<li><b>HideMenubar</b> - A flag specifying whether to hide the viewer application's menu bar when the document is active.</li>
<li><b>HideWindowUI</b> - A flag specifying whether to hide user interface elements in the document's window (such as scroll bars and navigation controls), leaving only the document's contents displayed.</li>
<li><b>FitWindow</b> - A flag specifying whether to resize the document's window to fit the size of the first displayed page.</li>
<li><b>CenterWindow</b> - A flag specifying whether to position the document's window in the center of the screen.</li>
<li><b>DisplayDocTitle</b> - A flag specifying whether to display the document's title in the top bar.</li>

<li>The predominant reading order for text. This entry has no direct effect on the document's contents or page numbering, but can be used to determine the relative positioning of pages when displayed side by side or printed <i>n-up</i> (choose one).
<ul>
<li><b>DirectionL2R</b> - Left to right</li>
<li><b>DirectionR2L</b> - Right to left (including vertical writing systems such as Chinese, Japanese, and Korean)</li>
</ul>
</li>

<li>The document's page mode, specifying how to display the document on exiting full-screen mode. It is meaningful only if the page mode is <b>PageModeFullScreen</b> (choose one).
<ul>
<li><b>NonFullScreenPageModeUseNone</b> - Neither document outline nor thumbnail images visible</li>
<li><b>NonFullScreenPageModeUseOutlines</b> - Document outline visible</li>
<li><b>NonFullScreenPageModeUseThumbs</b> - Thumbnail images visible</li>
<li><b>NonFullScreenPageModeUseOC</b> - Optional content group panel visible</li>
</ul>
</li>
<li><b>PrintScalingNone</b> - Sets the print scaling to 'None'</li>
</ul>
</div><a class="top" href="#top">Go to top of the page</a><a xmlns="" name="pagelabels"></a><div class="title">Pagelabels:</div><div xmlns="http://www.w3.org/1999/xhtml">
If you set the viewerpreferences to mode PageModeUseThumbs,
you get a 'thumbnails' view of you document, showing a small version of every page.
Under each thumbnail, you have a label.
If you want to change the style of these page labels, you have to create a <a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/pdf/PdfPageLabels.html">PdfPageLabels object</a>
and add a new style, content or pagenumber value, starting from a certain 'real' pagenumber.<br xmlns="http://www.w3.org/1999/xhtml">
These are the different styles you can use:
<ul>
<li>PdfPageLabels.DECIMAL_ARABIC_NUMERALS</li>
<li>PdfPageLabels.UPPERCASE_ROMAN_NUMERALS</li>
<li>PdfPageLabels.LOWERCASE_ROMAN_NUMERALS</li>
<li>PdfPageLabels.UPPERCASE_LETTERS</li>
<li>PdfPageLabels.LOWERCASE_LETTERS</li>
<li>PdfPageLabels.EMPTY</li>
</ul>
<pre class="commandline">pageLabels.addPageLabel(1, PdfPageLabels.LOWERCASE_ROMAN_NUMERALS);
pageLabels.addPageLabel(5, PdfPageLabels.DECIMAL_ARABIC_NUMERALS);
pageLabels.addPageLabel(8, PdfPageLabels.DECIMAL_ARABIC_NUMERALS, "A-", 8);</pre>
The first line says that the labels starting on the 'real' page 1 should be lowercase roman numerals.
The second line says that the labels starting on the 'real' page 5 should be arabic numerals. The labels will start at 1, so the real page 5 will be labeled with the the 'logical pagenumber' 1.
The third line says that the labels starting on the 'real' page 8 should be arabic numbers, prefixed with the String "A-". The logical numbering should start with page 8 (otherwise the first label would be "A-1").
<div id="example">
					Example: java
					<a xmlns="" href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/PageLabels.java">
						com.lowagie.examples.objects.bookmarks.PageLabels</a><br>Creates a document with pagelabels: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/PageLabels.pdf">PageLabels.pdf</a><br></div>
</div><a class="top" href="#top">Go to top of the page</a><a name="layers"></a><div class="title">Optional Content:</div><div xmlns="http://www.w3.org/1999/xhtml">
If you set the viewerpreferences to mode PageModeUseOC (only since PDF version 1.5), you will be able to turn on or off different layers in the document.
You can read all about these layers in the chapter on <a xmlns="" href="./../..directcontent/optionalcontent/index.html#">Optional Content</a>.
<div id="example">
					Example: java
					<a href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/Layers.java">
						com.lowagie.examples.objects.bookmarks.Layers</a><br>Creates a document with text in different layers: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/Layers.pdf">Layers.pdf</a><br></div>
</div><a class="top" href="#top">Go to top of the page</a><a name="bookmarks"></a><div class="title">Bookmarks:</div><div xmlns="http://www.w3.org/1999/xhtml">
If you set the viewerpreferences to mode PageModeUseOutlines, you get an outline tree that can be used as a Table-Of-Content or as a list with bookmarks.
To construct this outline tree, you need to get the rootoutline from the writer object. To this root, you can add, new <a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/pdf/PdfOutline.html">PdfOutline</a> objects:
<pre xmlns="http://www.w3.org/1999/xhtml" class="commandline">PdfOutline root = writer.getDirectContent().getRootOutline();
new PdfOutline(cb.getRootOutline(), someDestination, "a bookmark");</pre>
In the <a xmlns="" href="./../../objects/bookmarks/index.html#destinations">next section</a>, you will learn how to create objects such as 'someDestination'.
In the example below, we use PageEvents to add an entry to the outline tree every time a new Paragraph is added to the document.
<div id="example">
					Example: java
					<a href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/Bookmarks.java">
						com.lowagie.examples.objects.bookmarks.Bookmarks</a><br>Creates a document with Bookmarks for every new Paragraph that is added: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/Bookmarks.pdf">Bookmarks.pdf</a><br></div>
</div><a class="top" href="#top">Go to top of the page</a><a name="destinations"></a><div class="title">Creating Destinations:</div><div xmlns="http://www.w3.org/1999/xhtml">
In the chapter on <a xmlns="" href="./../../objects/anchors/index.html#localgoto">Anchors</a>,
we already defined destinations, by giving a name to a Chunk object (<a href="http://itext.ugent.be/library/api/com/lowagie/text/Chunk.html#setLocalDestination(java.lang.String)">setLocalDestination</a>).
The position on the page of this Chunk defined the destination.<br xmlns="http://www.w3.org/1999/xhtml">
In this section, we are going to create destinations of the types:
Destination.XYZ, Destination.FIT, Destination.FITH, Destination.FITV, Destination.FITR, Destination.FITB, Destination.FITBH or Destination.FITBV,
using one of the following constructors:
<ul>
<li><a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/pdf/PdfDestination.html#PdfDestination(int)">public PdfDestination(int type)</a>
can be used for types FIT and FITB.
<b xmlns="http://www.w3.org/1999/xhtml">FIT</b> points to the current page, with its contents magnified just enough to fit the entire page within the window
both horizontally and vertically.
<b>FITB</b> does the same, but the contents are magnified just enough to fit
its bounding box.</li>
<li><a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/pdf/PdfDestination.html#PdfDestination(int,%20float)">public PdfDestination(int type, float parameter)</a>
can be used for types FITH, FITV, FITBH and FITBV.<br xmlns="http://www.w3.org/1999/xhtml">
If type equals <b>FITBV</b>, the height of the bounding box of a page will fit the window of the Reader.
The parameter will specify the x coordinate of the left edge of the window.<br>
If the type equals <b>FITV</b> the height of the entire page will fit the window and
the parameter will specify the x coordinate of the left edge.<br>
If type equals <b>FITBH</b>, the width of the bounding box of a page will fit the window of the Reader.
The parameter will specify the y coordinate of the top edge of the window.<br>
If the type equals <b>FITH</b> the width of the entire page will fit the window and
the parameter will specify the y coordinate of the top edge.<br>
</li>
<li><a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/pdf/PdfDestination.html#PdfDestination(int,%20float,%20float,%20float)">public PdfDestination(int type, float left, float top, float zoom)</a>
can be used for type <b xmlns="http://www.w3.org/1999/xhtml">XYZ</b> with the coordinates (left, top) as the top-left corner of the destination window
and the contents of the page magnified by the factor zoom.
A negative value for any of the parameters left or top, or a zoom value of 0
specifies that the current value of that parameter is to be retained unchanged.
</li>
<li><a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/pdf/PdfDestination.html#PdfDestination(int,%20float,%20float,%20float,%20float)">public PdfDestination(int type, float left, float bottom, float right, float top)</a>
can be used for type <b xmlns="http://www.w3.org/1999/xhtml">FITR</b> the destination will be a rectangle specified by the coordinates left, bottom, right, and top.
If the required horizontal and vertical magnification factors are different,
use the smaller of the two, centering the rectangle within the window in the other dimension.
</li>
</ul>
When a destination is created, it is not linked to a certain page in the document.
Only when add the destination the outline tree, it will point to the 'current' page.
In the chapter on <a xmlns="" href="./../../objects/anchors/index.html#localgoto">Anchors</a>,
we already used some destinations in Actions. Now we are going to use destinations as targets for our bookmarks.
We will draw several crosses on a page and jumps to these crosses from the outline tree.
<pre xmlns="http://www.w3.org/1999/xhtml" class="commandline">PdfDestination d1 = new PdfDestination(PdfDestination.XYZ, 300, 800, 0);
PdfDestination d2 = new PdfDestination(PdfDestination.FITH, 500);
PdfDestination d3 = new PdfDestination(PdfDestination.FITR, 200, 300, 400, 500);
PdfDestination d4 = new PdfDestination(PdfDestination.FITBV, 100);
PdfDestination d5 = new PdfDestination(PdfDestination.FIT);</pre>
<div id="example">
					Example: java
					<a xmlns="" href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/Destinations.java">
						com.lowagie.examples.objects.bookmarks.Destinations</a><br>Creates a document with destinations that can be called from Bookmarks: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/Destinations.pdf">Destinations.pdf</a><br></div>
</div><a class="top" href="#top">Go to top of the page</a><a name="outlineactions"></a><div class="title">Outlines and Actions:</div><div xmlns="http://www.w3.org/1999/xhtml">
In the previous examples we used the outline tree to jump to a certain <a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/pdf/PdfDestionation.html">PdfDestination</a>,
but we can also use a <a href="http://itext.ugent.be/library/api/com/lowagie/text/pdf/PdfOutline.html#constructor_summary">PdfOutline</a> to trigger a
<a href="http://itext.ugent.be/library/api/com/lowagie/text/pdf/PdfAction.html">PdfAction</a> (see the chapter on <a href="./../../objects/anchors/index.html#actions">Actions</a>).
<pre xmlns="http://www.w3.org/1999/xhtml" class="commandline">PdfOutline root = writer.getDirectContent().getRootOutline();
new PdfOutline(root,
	new PdfAction("http://www.lowagie.com/iText"), "Bruno's iText site");
new PdfOutline(other,
	PdfAction.javaScript("app.alert('Hello');\r", writer), "Say Hello");</pre>
<div id="example">
					Example: java
					<a xmlns="" href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/OutlineActions.java">
						com.lowagie.examples.objects.bookmarks.OutlineActions</a><br>Creates a document with external destinations or actions that can be called from Bookmarks: see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/OutlineActions.pdf">OutlineActions.pdf</a> <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/remote.pdf">remote.pdf</a><br></div>
</div><a class="top" href="#top">Go to top of the page</a><a name="chapter"></a><div class="title">the Chapter and Section object:</div><div xmlns="http://www.w3.org/1999/xhtml">
If all the examples above are overkill, if you only need a simple tree
with some chapters and (sub)sections, you needn't define destinations and
add them to a rootoutline or a parent outline. You can simply use the
objects <a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/Chapter.html">Chapter</a> 
and <a href="http://itext.ugent.be/library/api/com/lowagie/text/Section.html">Section</a>.
They build a tree and number titles automatically.
<pre xmlns="http://www.w3.org/1999/xhtml" class="commandline">Paragraph cTitle = new Paragraph("This is chapter 1", chapterFont);
Chapter chapter = new Chapter(cTitle, 1);
Paragraph sTitle = new Paragraph("This is section 1 in chapter 1", sectionFont);
Section section = chapter.addSection(sTitle, 1);</pre>
<div class="subtitle">Some caveats:</div>
<ul>
<li>The content of a complete Chapter (including subsections) is only 'flushed'
to the writer at the moment you add the chapter to the document.
<ul>
<li>avoid mixing Chapter.add() and Document.add invocations.
If you add a Chunk1 to a Chapter first, then a Chunk2 to the document and
finally add the chapter, Chunk2 will come before Chunk1 in the resulting
document.</li>
<li>avoid creating Chapters that are too large: all the chapter content
is kept in memory as long as you don't add the chapter to the doc.</li>
</ul>
</li>
<li>Every chapter starts on a new page automatically. If you want to have
a section within a chapter starting on a new page, you will have to use
<a xmlns="" href="http://itext.ugent.be/library/api/com/lowagie/text/Chunk.html#NEXTPAGE">Chunk.NEXTPAGE</a>.</li>
</ul>
<div id="example">
					Example: java
					<a href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/ChapterSection.java">
						com.lowagie.examples.objects.bookmarks.ChapterSection</a><br>Creates a document with Chapters and Sections (automatic outlines): see
						 <a href="http://itext.ugent.be/library/com/lowagie/examples/objects/bookmarks/ChapterSection.pdf">ChapterSection.pdf</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:48
			Copyright &copy; 1999-2005
			Bruno Lowagie, Paulo Soares<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=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=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=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><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></div></body></html>