Example: On-the-Fly Table of Contents

Top Previous Topic Next Topic  Print this topic

In this example, the special job-info() function will be used to create and format a table of contents.

 

How to Use the job-info() Function

 

A very generic information that functions when included in any DAL job will be presented below.

 

A job info document looks alike to any XFD or XSLT document, with the only difference being in the input xml, which has to point to the job-info() element.

 

 

<xfj:document id="toc">

      <xfj:external-content src="url(toc_xfd_url)"/>

      <xfj:input-xml src="job-info()"/>

</xfj:document>

 

 

The toc_xfd_url represents the URL or base64 bytes of the template (XSLT or XFD) to use when rendering the job info file.

 

The XFD/XSL template must reference the fields in the job info document.

 

In the following example, all of the documents except for this one are selected (the 'toc' id is excluded from the resulting XML node set):

 

 

<xfd:block-repeat xpath="/xfj:job-info/xfj:document-info[@id != 'toc']">

       <fo:block text-align-last="justify">

               <xfd:field xpath="@id"/> - <xfd:field xpath="@title"/>

               <fo:leader leader-pattern="dots"/>

               <xfd:field xpath="@page"/>

       </fo:block>

</xfd:block-repeat>

 

 

The output of the above template should be the following:

 

 

doc1 - Title of Doc 1...................................3

doc2 - Title of Doc 2...................................7

doc3 - Title of Doc 3..................................10

 

 

The structure of the in-memory job info file is described here.

 

Full Job Example with Table of Contents

 

The sample DAL Job generates a final PDF output with the following features:

 

1. Title Page

2. Table of Contents (Index) – this is generated from an input XFD template; the job-info() parameter is the one responsible with transmitting the correct page references to the template

3. Content pages – includes 2 documents, each of them having 2 pages: the first document is a PDF file and the second one is generated from an XFD template (with dynamic content from a XML Data Source)

4. An overlay (header with page numbers and footer) has been set. This is applied to all of the pages, except for the Title Page and the Table of Contents.

5. The Table of Contents is not included in the page count.

 

 

<?xml version="1.0" encoding="utf-8"?>

<xfj:job xmlns:xfj="http://www.ecrion.com/xfj/1.0">

       <xfj:output mime-type="application/pdf"/>        

       <xfj:overlay id="PageNumber" z-index="1">

               <xfj:apply-rules>

                       <xfj:match rule="exclude(title)" />

                       <xfj:match rule="exclude(toc)" />                        

                       <xfj:match rule="all" />                        

               </xfj:apply-rules>                

               <xfj:external-content src="url(.\resources\PageNumber.fo)" />

         </xfj:overlay>        

       <xfj:document id="title" title="Title Page" exclude-from-page-count="true">

               <xfj:external-content src="url(.\resources\Title_page.pdf)"/>

       </xfj:document>

       <xfj:document id="toc" exclude-from-page-count="true">

               <xfj:external-content src="url(.\resources\TOC.xfd)"/>

               <xfj:input-xml src="job-info()"/>

       </xfj:document>

       <xfj:document id="doc1" title="Document No. 1">

               <xfj:external-content src="url(.\resources\Document1.pdf)"/>

       </xfj:document>        

       <xfj:document id="doc3" title="Document No. 2">

               <xfj:apply-local-template src="url(.\resources\Template2.xfd)"/>

               <xfj:external-content src="url(.\resources\data.xml)"/>

       </xfj:document>        

</xfj:job>

 

 

 

Output:

 

1