<?xml version="1.0" encoding="iso-8859-1" standalone="no" ?> 
<!DOCTYPE document SYSTEM "../rml_1_0.dtd"> 
<document filename="test_018_toc_outline.pdf"> 
	<docinit><name id="imageName" value="image13.gif"/>
	</docinit>
<template pageSize="(595, 842)" leftMargin="72" showBoundary="0">
    

    <pageTemplate id="first">
    	<!--this has no page number-->
		<pageGraphics>
			<setFont name="Helvetica-Bold" size="18"/>
		    <drawString x="35" y="783">RML Example 19: Outline</drawString>
			<image file="logo_no_bar.png" preserveAspectRatio="1" x="488" y="749" width="72" height="72"/>
    		<image file="strapline.png" preserveAspectRatio="1" x="35" y="0" width="525" />
			<image x="72" y="800" width="72" height="12" file="rml:imageName"/>
		</pageGraphics>
		<frame id="second" x1="35" y1="45" width="525" height="590"/>
	</pageTemplate>

    <pageTemplate id="main">
    	<!-- this does special maths to number pages from whatever page the real story started on-->
		<pageGraphics>
			<setFont name="Helvetica-Bold" size="18"/>
		    <drawString x="35" y="783">RML Example 19: Outline</drawString>
			<image file="logo_no_bar.png" preserveAspectRatio="1" x="488" y="749" width="72" height="72"/>
    		<image file="strapline.png" preserveAspectRatio="1" x="35" y="0" width="525" />
                <setFont  name="Helvetica" size="9pt"/>
			<drawRightString x="523" y="35"><evalString default="XXX"><pageNumber/>-<getName id="pageZero"/></evalString></drawRightString>
			<image x="72" y="800" width="72" height="12" file="rml:imageName"/>
		</pageGraphics>
		<frame id="first" x1="1in" y1="1in" width="6.27in" height="8.69in"/>
	</pageTemplate>

</template>

<stylesheet>
	<initialize>
	<alias id="style.normal" value="style.Normal"/>
	</initialize>

	<paraStyle name="h1"
	fontName="Helvetica-Bold"
	fontSize="16"
	leading="20"
	spaceBefore = "0.5 cm"
	/>
	
    <paraStyle name="body"
	fontName="Helvetica"
	fontSize="12"
	spaceBefore="6"
	leading="14"
	/>

	<paraStyle name="toc_level1"
        fontName="Times-Bold"
        fontSize="12"
        spaceBefore="3"
        leading="14"
    />
    
    <paraStyle name="intro"  fontName="Helvetica" fontSize="12" leading="12" spaceAfter="12"/>
	<blockTableStyle id="simple">
		<blockAlignment value="left"/>
		<blockFont name="Helvetica"/>
		<lineStyle kind="GRID" colorName="black"/>
		<lineStyle kind="OUTLINE" colorName="black" thickness="2"/>
	</blockTableStyle>

    
</stylesheet>

<story>
<storyPlace x="35" y="660" width="525" height="73" origin="page">
<para style="intro">RML (Report Markup Language) is ReportLab's own language for specifying the appearance of a printed page, which is converted into PDF by the utility rml2pdf.</para>
<hr color="white" thickness="8pt"/>
<para style="intro">These RML samples showcase techniques and features for generating various types of ouput and are distributed within our commercial package as test cases. Each should be self explanatory and stand alone.</para>
<illustration height="3" width="525" align="center">
<fill color= "(0,0.99,0.97,0.0)" />
<rect x="0" y = "-12" width="525" height="3" round="1" fill="1" stroke = "Yes" />
</illustration>
</storyPlace>

<!--This is a name the form can retrieve later.  Tags like this track and memorize the pages
for later on-->
<namedString id="pageZero"><pageNumber/></namedString>
<para style="h1">Table Of Contents (TOC) example</para>


	<para style="body">
	This demonstrates the fast way to generate a table of contents.
	The table of contents below is generated dynamically.  We reserve
	a fixed size box to hold the TOC below (6x3 inches in this case),
	and use a deferred form to draw it.  If you can safely estimate the
	maximum size of the TOC (and if it fits on one page), this lets
	you generate one in a single formatting pass.</para>
	
	<para style="body">
	If the TOC might span pages, then don't do the deferred form; just put
	the TOC table inline within the document, using namedString and getName.
	RML will automatically do multiple passes over the document (usually 2
	but it can be 3) until all cross references are resolved accurately.</para>
	
<para style="body">
We also did some cunning trickery with the page numbers to make the
second page show 'page 1' - see the source.  You can do basic page
number maths to number sections distinctly.</para>
<spacer length="24"/>
<illustration width="6in" height="3in">
	<pageGraphics>
		<doForm name="TOC"/>
	</pageGraphics>
</illustration>


<!-- want all pages from the first to use the template which has page numbers at the bottom-->
<setNextTemplate name="main"/>

<nextFrame/>

<para style="h1">Chapter 1: About this page</para>
<namedString id="label1">Chapter 1</namedString>
<namedString id="page1"><evalString default="XXX"><pageNumber/>-<getName id="pageZero"/>+1</evalString></namedString>
	<para style="body">About these pages: the code behind this pdf should give an example of how to set up a table
    of contents. 
    You'll see the form for the table of contents (headed 'form name="TOC"') is defined at the end of the code.
    The two most important tags and the (ones that must match here)are 
    namedString id="label3" and the related getName id="label3".
    The first sets a value for the contents page number, the second retrieves it.
    
     
    Ignore the following pseudo-bio babble, it's there for padding</para>

	<para style="h1">Politics of Foramenifera </para>
	<para style="body">Globorotalia Menardii coils according to water temperature and prevailing political situations. 
    Preferring alkaline rather than acidic environments they are however intuitively left-wing</para>

	<para style="h1">Drosophila Melanogaster </para>
	<para style="body">How fruit flies changed my life. Blah blah waffle waffle blah blah yawn yawn
    ....................................... </para>

	
<nextFrame/>
<para style="h1">CHAPTER2</para>
<namedString id="label2">Chapter 2</namedString>
<namedString id="page2"><evalString default="XXX"><pageNumber/>-<getName id="pageZero"/>+1</evalString></namedString>

    <para style="h1">Politics of Foramenifera</para>
	<para style="body">Globorotalia Menardii coils according to water temperature and prevailing political situations. 
    Preferring alkaline rather than acidic environments they are intuitively left-wing</para>

	<para style="h1">Drosophila Melanogaster </para>
	<para style="body">How fruit flies changed my life. Blah blah waffle waffle blah blah yawn yawn
    ....................................... </para>
<namedString id="imageName">image45.gif</namedString>
<nextFrame/>
	
<para style="h1">CHAPTER3</para>
<namedString id="label3">Chapter3</namedString>
<namedString id="page3"><evalString default="XXX"><pageNumber/>-<getName id="pageZero"/>+1</evalString></namedString>

<para style="h1">Acrocladium Cuspidatum</para>
	<para style="body">A meaningful relationship with Moss</para>

	<para style="h1">Rattus rattus</para>
	<para style="body">So bad they named him twice Blah blah waffle waffle blah blah yawn yawn
    ....................................... </para>
<nextFrame/>
	<para style="body">more rubbish about ratty and so forth
    ....................................... </para>
<namedString id="imageName">image67.gif</namedString>
<nextFrame/>


<para style="h1">CHAPTER4</para>
<namedString id="label4">Chapter4</namedString>
<namedString id="page4"><evalString default="XXX"><pageNumber/>-<getName id="pageZero"/>+1</evalString></namedString>

<para style="h1">Namby Pamby</para>
	<para style="body">Lilac scented satin trousers</para>

	<para style="h1">Ganesh the elephant god dances on heads with Kali</para>
	<para style="body">So bad they named him thrice Blah blah waffle waffle blah blah yawn yawn
    ....................................... </para>
	
	
<nextFrame/>
<para style="h1">Last Chapter</para>
<namedString id="labelLast">Last Chapter</namedString>
<namedString id="pageLast"><evalString default="XXX"><pageNumber/>-<getName id="pageZero"/>+1</evalString></namedString>
	<para style="body">
Blah blah waffle waffle blah blah yawn yawn.......................................
Blah blah waffle waffle blah blah yawn yawn.......................................
Blah blah waffle waffle blah blah yawn yawn.......................................
	</para>

<!--This is where we define the form for the TOC.
We use a standard 'trick' to get a graphics context:  a zero-sized illustration consumes no space
at the end of the story, but lets us define a graphical form, which has been referred to earlier in the
document.  At this point, the engine will know all the page numbers so can do the job in one pass.

-->

<illustration width="0" height="0">
	<form name="TOC">
		<!--this one uses a table, which is much easier.  However, it presumes you can set a maximum
		space for it; this approach wull not handle 'flopping onto page two', and if the table exceeds the
		size of the place then it will not appear.-->
		<place x="0" y="0" width="6in" height="3in">
			<para style="h1">Table of Contents</para>
			<blockTable colWidths="5in,1in" style="simple">
				<!--your generation code would have collected an array of chapter names and ids and loop
				over to generate them here
				Note we 'did some maths' to make sure the TOC references the 'as displayed'
				page numbers and not the real ones, irrespective of how many front pages we have
				-->
				<tr>
					<td><para style="toc_level1"><getName id="label1"/></para></td>
					<td><para style="toc_level1"><evalString><getName id="page1"/> - <getName id="pageZero"/></evalString></para></td>
				</tr>
				<tr>
					<td><para style="toc_level1"><getName id="label2"/></para></td>
					<td><para style="toc_level1"><evalString><getName id="page2"/> - <getName id="pageZero"/></evalString></para></td>
				</tr>
				<tr>
					<td><para style="toc_level1"><getName id="label3"/></para></td>
					<td><para style="toc_level1"><evalString><getName id="page3"/> - <getName id="pageZero"/></evalString></para></td>
				</tr>
				<tr>
					<td><para style="toc_level1"><getName id="label4"/></para></td>
					<td><para style="toc_level1"><evalString><getName id="page4"/> - <getName id="pageZero"/></evalString></para></td>
				</tr>
				<tr>
					<td><para style="toc_level1"><getName id="labelLast"/></para></td>
					<td><para style="toc_level1"><evalString><getName id="pageLast"/> - <getName id="pageZero"/></evalString></para></td>
				</tr>
			</blockTable>
		</place>		
	</form>
</illustration>



</story>
</document>
