<?xml version="1.0" encoding="iso-8859-1" standalone="no" ?> 
<!DOCTYPE document SYSTEM "rml_1_0.dtd"> 
{{def(data, options)}}
<document filename="longExample.pdf"> 
	<docinit useCropMarks="yes">
		<cropMarks markColor="green" markWidth="0.5" markLength="18" borderWidth="36"/>
		<!--here is how to set values for the first template to see -->
		<name id="chapterColor" value="grey"/>
		<name id="title" value="Examples of long document features"/>
		<!-- now we register font -->
		<registerTTFont faceName="Vera" fileName="Vera.ttf" />
		<registerTTFont faceName="VeraBold" fileName="VeraBd.ttf" />
        <registerTTFont faceName="Geneva" fileName="fonts/geneva.ttf"/>
		<startIndex/>

	</docinit>

	<template pageSize="(595, 842)" leftMargin="72" showBoundary="0">
		<!-- here we define templates -->
		<pageTemplate id="cover">
			<pageGraphics>
				<setFont name="Geneva" size="20"/>
				<image file="images/logo_bg.gif" x="213" y="600" width="182" height="113"/>
				<drawCentredString x="297" y="520"><getName id="title"/></drawCentredString>
			</pageGraphics>
			<frame id="first" x1="72" y1="72" width="451" height="400"/>
		</pageTemplate>

		<pageTemplate id="description">
			<pageGraphics>
				<setFont name="Geneva" size="20"/>
				<drawCentredString x="297" y="780"><getName id="title"/></drawCentredString>
			</pageGraphics>
			<frame id="first" x1="72" y1="72" width="451" height="680"/>
		</pageTemplate>

        <pageTemplate id="navigation">
            <pageGraphics>
                <setFont name="Geneva" size="27"/>
                <drawRightString x="578" y="737"><getName id="title"/></drawRightString>
            </pageGraphics>
        
            <frame id="first" x1="10%" y1="8%" width="80%" height="75%"/>
        </pageTemplate>

		<pageTemplate id="main">
			<pageGraphics>
				<!-- pageGraphics is parsed once, but yields a collection -->
				<!-- of drawing operations which are done lazily each time -->
				<!-- we start a page.  Therefore certain elements can be dynamic. -->
				<!-- We have a dynamic chapter name, page number, and colour -->
				<!-- selected for the bars. -->
				<setFont name="Geneva" size="18"/>
				<drawRightString x="523" y="800"><getName id="chapterName"/></drawRightString>
				<setFont name="Geneva" size="8"/>
				<drawRightString x="523" y="20"><pageNumber countingFrom="2"/></drawRightString>
				<fill color="rml:chapterColor"/>
				<rect x="60" y="36" width="475" height="16" fill="yes" stroke="0"/>
				<rect x="60" y="780" width="475" height="16" fill="yes" stroke="0"/>
			</pageGraphics>
			<frame id="first" x1="1in" y1="1in" width="6.27in" height="9.69in"/>
		</pageTemplate>
 	</template>

	<stylesheet>
		<paraStyle name="normal"
				   fontName="Vera"
				   fontSize="10"
				   spaceBefore="6"
				   alignment="justify"
				   />


		<!-- parent attribute allows one style to inherit from another -->
       <paraStyle name="indexstyle" parent="normal" fontSize="8"/>		

	   <!-- this style simulates bullet list <para style="bulletList" bulletText="l"></para> -->
       <paraStyle name="bulletList"
				  parent="normal"
				  bulletFontName="ZapfDingbats"
				  bulletFontSize="5"
				  bulletIndent="20"
				  leftIndent="35"
				  spaceAfter="6"
				  />

		<paraStyle name="code"

				   fontName="Courier"
				   fontSize="8"
				   leftIndent="36"
				   textColor="blue"
				   />


        <blockTableStyle id="tocTableStyle">
            <blockTopPadding length="3"/>
            <blockBottomPadding length="3"/>
            <blockLeftPadding length="0"/>
            <blockRightPadding length="0"/>
            <blockFont name="VeraBold" size="12"/>
            <blockTextColor colorName="black"/>
			<blockValign value="MIDDLE"/>
        </blockTableStyle>

		<blockTableStyle id="indexTableStyle">
			<blockAlignment value="left"/>
			<blockValign value="top"/>
			<blockBottomPadding length="0" start="0,0" stop="-1,-1"/>
			<blockLeftPadding length="0" start="0,0" stop="-1,-1"/>
			<blockTopPadding length="0" start="0,0" stop="-1,-1"/>
			<blockRightPadding length="0" start="0,0" stop="-1,-1"/>
		</blockTableStyle>

	</stylesheet>

	<story firstPageTemplate="cover">
		
		<setNextTemplate name="description"/>
		<nextPage/>
		<outlineAdd>Introduction</outlineAdd>
		<para style="normal">This example shows how to use various features commonly found in multi-chapter documents. Further explanatory comments can be found in the RML code.</para>

		<para style="bulletList" bulletText="l">Creating a table of contents in one pass:</para>
		<para style="bulletList" bulletText="">
			When creating a table of contents we don't know the page numbers in advance, so we use a  &lt;doForm/&gt; tag with unique id instead. 
		</para>
		<xpre style="code"><![CDATA[<illustration width="30" height="10">]]></xpre>
		<xpre style="code"><![CDATA[    <doForm name="pagenum_section_1"/>]]></xpre>
		<xpre style="code"><![CDATA[</illustration>]]></xpre>
		<para style="bulletList" bulletText="">
			Then at the beginning of each chapter we create an invisible form to hold the current page number.
		</para>
		
		<xpre style="code"><![CDATA[<illustration width="0" height="0"></illustration>]]></xpre>
		<xpre style="code"><![CDATA[    <form name="pagenum_section_1">]]></xpre>
		<xpre style="code"><![CDATA[        <setFont name="Geneva" size="9"/>]]></xpre>
		<xpre style="code"><![CDATA[        <drawString x="0" y="0"><pageNumber countingFrom="2"/></drawString>]]></xpre>
		<xpre style="code"><![CDATA[    </form>]]></xpre>
		<xpre style="code"><![CDATA[</illustration>]]></xpre>

		<para style="bulletList" bulletText="l">Creating outlines:</para>
		<xpre style="code"><![CDATA[<outlineAdd>Table of Contents</outlineAdd>]]></xpre>
		<para style="bulletList" bulletText="l">Internal links to current PDF document:</para>
		<para style="bulletList" bulletText="">Destination attribute creates a link to a bookmark element.</para>
		<xpre style="code"><![CDATA[<td destination="bookmark_chapter_1">Chapter 1</td>]]></xpre>
		<xpre style="code"><![CDATA[<bookmark name="bookmark_chapter_1"/>]]></xpre>
		<para style="bulletList" bulletText="l">Dynamic headers and footers:</para>
		<para style="bulletList" bulletText="">In page templates, a getName element can be used.</para>
		<xpre style="code"><![CDATA[<pageTemplate id="main">]]></xpre>
		<xpre style="code"><![CDATA[    <pageGraphics>]]></xpre>
		<xpre style="code"><![CDATA[        <drawRightString x="523" y="800"><getName id="chapterName"/></drawRightString>]]></xpre>
		<xpre style="code"><![CDATA[    </pageGraphics>]]></xpre>
		<xpre style="code"><![CDATA[    <frame id="first" x1="1in" y1="1in" width="6.27in" height="9.69in"/>]]></xpre>
		<xpre style="code"><![CDATA[</pageTemplate>]]></xpre>
		<para style="bulletList" bulletText="">Then at the beginning of each chapter a namedString element is used to set the chapter name.</para>
 		<xpre style="code"><![CDATA[<namedString id="chapterName">Chapter 1</namedString>]]></xpre>
		<para style="bulletList" bulletText="l">Creating a word index:</para>
		<para style="bulletList" bulletText="">First start the index in the docInit section</para>
		<xpre style="code"><![CDATA[<docinit>]]></xpre>
		<xpre style="code"><![CDATA[    <startIndex/>]]></xpre>
		<xpre style="code"><![CDATA[</docinit>]]></xpre>
		<para style="bulletList" bulletText="">Index tag is used for creating the reference.</para>
		<xpre style="code"><![CDATA[<index item="lorem"/>]]></xpre>
		<para style="bulletList" bulletText="">Show index tag is then used to create an index page.</para>
		<xpre style="code"><![CDATA[<showIndex style="indexstyle" dot="-" tableStyle="indexTableStyle" headers="1"/>]]></xpre>
		<para style="bulletList" bulletText="l">Style inheritance</para>
		<para style="bulletList" bulletText="l">Basic tables usage</para>

		<!-- namedString are defined before nextFrame is used -->
		<namedString id="title">Table of Contents</namedString>
		<setNextTemplate name="navigation"/>
		<nextFrame/>
		<outlineAdd>Table of Contents</outlineAdd>
		<spacer length="10"/>    
		
		<!-- for the master table of contents, we make a first pass -->
		<!-- creating a table with a row for each section.  This will have -->
		<!-- 3 columns:  number, name, color,  page  -->
		<blockTable style="tocTableStyle" colWidths="5%,27%,47%,20%">

			{{for (id, title, title_num, color) in data['chapters']}}
			
			<tr>
				<!-- each table cell acts like a big hyperlink to the -->
				<!-- corresponding part of the document - the bookmark attribute. -->
				<td destination="bookmark_chapter_{{id}}">{{id}}.</td>
				<td destination="bookmark_chapter_{{id}}">{{title}}</td>
				<td destination="bookmark_chapter_{{id}}">
					<illustration width="120" height="10">
						<fill color="{{color}}"/>
						<rect x="0" y="1" width="220" height="5" fill="1" stroke="0"/>
					</illustration>
				</td>
				<td destination="bookmark_chapter_{{id}}" align="right">
					<!-- the fourth cell is the one with the page numbers. -->
					<!-- These are not known yet, so we use a PDF feature:  we refer to a named -->
					<!-- but not-yet-defined graphic object ('form') with a unique name such -->
					<!-- as "bookmark_chapter_3", and then when -->
					<!-- drawing the beginning of that section, we define the form.  Adobe Reader -->
					<!-- sorts it all out for us when the PDF is displayed, allowing single-pass -->
					<!-- generation. -->
					<illustration width="30" height="10">
						<doForm name="pagenum_section_{{id}}"/>
					</illustration>
					
				</td>
			</tr>
			{{script}} next = id + 1 {{endscript}}
			{{endfor}}

			<tr>

				<td destination="start_of_index">{{next}}.</td>
				<td destination="start_of_index">Index</td>
				<td destination="start_of_index"></td>
				<td destination="start_of_index" align="right">
					<illustration width="30" height="10">
						<doForm name="pagenum_index"/>
					</illustration>
				</td>
			</tr>

		</blockTable>

		{{ for chapter in data['content'] }}
 		<namedString id="chapterName">{{chapter['title_num']}}</namedString>
 		<namedString id="chapterColor">{{chapter['color']}}</namedString>
		<setNextTemplate name="main"/>
		<nextPage/>
		<para>
			<index item="lorem"/>
			<index item="ipsum"/>
		</para>
		<outlineAdd>{{chapter['title']}}</outlineAdd>
		<bookmark name="bookmark_chapter_{{chapter['num']}}"/>		
		
		<!--draw an 'invisible form' with the current page number-->
		<illustration width="0" height="0">
			<form name="pagenum_section_{{chapter['num']}}">
				<setFont name="Helvetica" size="9"/>
				<drawString x="0" y="0"><pageNumber countingFrom="2"/></drawString>
			</form>
		</illustration>

		<h2>{{chapter['title_num']}}</h2>
		{{ for para in chapter['content'] }}
		<para style="normal">{{para['data']}}</para>
		{{ endfor }}
		{{ endfor }}

		<namedString id="title">Index</namedString>
		<setNextTemplate name="navigation"/>
		<nextFrame/>

		<spacer length="10"/>    
		<bookmark name="start_of_index"/>
		<illustration width="0" height="0">
			<form name="pagenum_index">
				<setFont name="Helvetica" size="9"/>
				<drawString x="0" y="0"><pageNumber countingFrom="2"/></drawString>
			</form>
		</illustration>

		<outlineAdd>Index</outlineAdd>
		<showIndex style="indexstyle" dot="-" tableStyle="indexTableStyle" headers="1"/>

	</story>
</document>
