Index: documentation/trunk/tutorials/xml-source/tutorial_en.xml
===================================================================
--- documentation/trunk/tutorials/xml-source/tutorial_en.xml	(revision 32905)
+++ documentation/trunk/tutorials/xml-source/tutorial_en.xml	(revision 32906)
@@ -1288,4 +1288,5 @@
 </Tutorial>
 -->
+<!--
 <Tutorial id="enhanced_pdf">
 <Title>
@@ -1450,5 +1451,5 @@
 </NumberedItem>
 </MajorVersion>
-<!--<MajorVersion number="3">
+<MajorVersion number="3">
 <NumberedItem>
 <Text id="fw-24a-3">Next we'll customize the <AutoText text="search"/> format statement to highlight the query terms in a PDF file when it is opened from the search result list. This requires Acrobat Reader 7.0 version or higher, and currently only works on a Microsoft Windows platform.</Text>
@@ -1498,5 +1499,229 @@
 </Format>
 </NumberedItem>
-</MajorVersion>-->
+</MajorVersion>
+<Text id="fw-24i">When the PDF icons are clicked in the search results, Acrobat will open the file with the search window open with the query terms highlighted.</Text>
+</Content>
+</Tutorial>
+-->
+<Tutorial id="enhanced_pdf">
+<Title>
+<Text id="ep-1">Enhanced PDF handling</Text>
+</Title>
+<SampleFiles folder="Word_and_PDF"/>
+<Version initial="3.09" current="3.09"/>
+<Content>
+  <Comment><Text id="ep-2">Prior to Greenstone 3.09, Greenstone shipped with a plugin called <AutoText text="PDFPlugin"/>. It was the plugin Greenstone used to convert PDF files to HTML using the third-party software <AutoText text="pdftohtml.pl" type="italics"/>. PDFPlugin allowed users to view PDF documents even if they didn't have the PDF software installed. Unfortunately, sometimes the formatting of the resulting HTML files was not so good. Earlier versions of this tutorial would provide some instruction on extra options to the PDFPlugin for producing a nicer version for display.</Text>
+  </Comment>
+  <Comment><Text id="ep-2a">Furthermore, the older pdftohtml process could not cope with much newer versions of PDF unless PDFPlugin's <Format>pdfbox_conversion</Format> option was switched on.</Text>
+  </Comment>
+  <Comment><Text id="ep-2b">Starting with Greenstone 3.09, some older pdf processing functionality has been restructured into <AutoText text="PDFv1Plugin"/>, while shifting the <Format>pdfbox_conversion</Format> option into <AutoText text="PDFv2Plugin"/>. PDFv2Plugin further makes use of third-party software <AutoText text="xpdf-tools" type="italics"/>, which better copes with newer PDFs (without requiring the <Format>pdfbox_conversion</Format> option to be activated). PDFv2Plugin comes with several new preconfigured settings to produce output files in html, text, image or image and text formats, that can better reflect the appearance of an input PDF document's pages. Behind the scenes, PDFv2Plugin is configured to use the third-party xpdf-tools or pdfbox software for each output setting.</Text>
+  </Comment>
+  <Comment><Text id="ep-2c">From Greenstone 3.09 onwards, PDFv2Plugin is added to a new collection's Document Plugins pipleline by default, in place of the now defunct PDFPlugin. In any instance where you particularly prefer the original PDFPlugin's HTML output for a PDF, you can now use PDFv1Plugin instead, as it still retains this functionality.</Text>
+  </Comment>
+<NumberedItem>
+<Text id="ep-3a">In the Librarian Interface, start a new collection called "PDF collection" and base it on <AutoText key="glidict::NewCollectionPrompt.NewCollection"/>.</Text>
+<Text id="ep-3b">In the <AutoText key="glidict::GUI.Gather"/> panel, drag just the PDF documents from <Path>sample_files &rarr; Word_and_PDF &rarr; Documents</Path> into the new collection. Also drag in the PDF documents from <Path>sample_files &rarr; Word_and_PDF &rarr; difficult_pdf</Path>.</Text>
+<Text id="ep-3b-1">In the <AutoText key="glidict::CDM.GUI.Plugins"/> section of the <AutoText key="glidict::GUI.Design"/> panel, you should find <AutoText text="PDFv2Plugin"/> in the plugins list (in place of the deprecated <AutoText text="PDFPlugin"/> that would have been present in the plugins list in older versions of Greenstone).</Text>
+<Text id="ep-3c">Go to the <AutoText key="glidict::GUI.Create"/> panel and build the collection. Examine the output from the build process.</Text>
+<Text id="ep-3d">If you had built the same collection with PDFv1Plugin instead of PDFv2Plugin, the build output would inform you that one of the documents could not be processed and you'd have seen the following building messages: "The file pdf05-notext.pdf was recognised but could not be processed by any plugin.", and "3 documents were processed and included in the collection. 1 was rejected".</Text>
+<Text id="ep-3e">However, since you built the collection of 4 pdfs with PDFv2Plugin, you will notice that all 4 documents could be processed.</Text>
+</NumberedItem>
+<NumberedItem>
+<Text id="ep-4a">Preview the collection and view the documents. Inspect <Path>pdf01</Path> and <Path>pdf03</Path> first. There's a table of contents is provided to the right. Clicking on a page in the table of contents will scroll to that page. Another way of navigating can be found to the left, where individual pages are listed vertically by page number and clicking the "plus" box next to a page will expand its contents. The pdfs have been sectionalised into groups of 10 pages, each group further containing a section for each individual page. If your pdf contained 10 or fewer pages, there won't two levels of sectionalising, just one.</Text>
+<Text id="ep-4b">If you visit a given page and try to select and copy the text, you can. These are not entirely images of the pdf's pages (like screenshots of a pdf page), but are HTML pages that combine the images of the background of each pdf page with the actual text of that page superimposed. The latter is what makes the text selectable.</Text>
+<Text id="ep-4c">If you return to GLI's Design pane and double click on PDFv2Plugin in Document Plugins, then you will see that the convert_to option is set to paged_pretty_html. This is the default PDF convert_to type and produces the kind of sectionalised HTML pages consisting of background images and superimposed text that you see with <Path>pdf01</Path> and <Path>pdf03</Path>.</Text>
+</NumberedItem>
+<NumberedItem>
+<Text id="ep-5">Next preview <Path>pdf05-notext.pdf</Path>. This is also similarly sectionalised, but the text is not selectable. That's because the original PDF file <Path>pdf05-notext.pdf</Path> contained no text, only images of text.</Text>
+</NumberedItem>
+<NumberedItem>
+<Text id="ep-6a">Now preview <Path>pdf06-weirdchars.pdf</Path>. Although also sectionalised, its contents look very strange. The reason for this will become apparent if you open the original document by double-clicking <Path>pdf06-weirdchars.pdf</Path> in GLI's Gather pane. Then in the open PDF, select as much of the text on its first page as possible. Copy that text and paste it in a text editor. You should see strange characters. This is why Greenstone's PDFv2Plugin wasn't able to extract legible text either.</Text>
+<Text id="ep-6b">Although Greenstone has processed all 4 documents, <Path>pdf06-weirdchars.pdf</Path> can be made to look better.</Text>
+</NumberedItem>
+<!--
+<Heading>
+<Text id="0333">Modes in the Librarian Interface</Text>
+</Heading>
+<Comment>
+<Text id="0334">The Librarian Interface can operate in different modes. The default mode is <AutoText key="glidict::Preferences.Mode.Librarian"/> mode. We can use <AutoText key="glidict::Preferences.Mode.Expert"/> mode to work out why the pdf file could not be processed.</Text>
+</Comment>
+<NumberedItem>
+<Text id="0335">Use the <AutoText key="glidict::Menu.File_Options"/> item on the <AutoText key="glidict::Menu.File"/> menu, <AutoText key="glidict::Preferences.Mode"/> tab, to switch to <AutoText key="glidict::Preferences.Mode.Expert"/> mode and then build the collection again. The <AutoText key="glidict::GUI.Create"/> panel looks different in <AutoText key="glidict::Preferences.Mode.Expert"/> mode because it gives more options: locate the <AutoText key="glidict::CreatePane.Build_Collection" type="button"/> button, near the bottom of the window, and click it. Now a message appears saying that the file could not be processed, and why. Amongst all the output, we get the following message: "Error: PDF contains no extractable text. Could not convert pdf05-notext.pdf to HTML format". pdftohtml.pl cannot convert a PDF file to HTML if the PDF file has no extractable text.</Text>
+</NumberedItem>
+<NumberedItem>
+<Text id="0336">We recommend that you switch back to <AutoText key="glidict::Preferences.Mode.Librarian"/> mode for subsequent exercises, to avoid confusion.</Text>
+</NumberedItem>
+-->
+<Heading>
+<Text id="ep-11">Using image format</Text>
+</Heading>
+<NumberedItem>
+<Text id="ep-12">PDF documents can be converted to a series of images, one per page. This requires ImageMagick and Ghostscript to be installed.</Text>
+</NumberedItem>
+<NumberedItem>
+<Text id="ep-13">In the <AutoText key="glidict::CDM.GUI.Plugins"/> section, configure <AutoText text="PDFv2Plugin"/>. Set the <AutoText text="convert_to"/> option to one of the image types, e.g. <AutoText text="pagedimg_jpg"/>. </Text>
+</NumberedItem>
+<MajorVersion number="3">
+<NumberedItem>
+<Text id="ep-14-3"><b>Build</b> the collection and <b>preview</b>. 
+All PDF documents have been processed again, still divided into a series of page sections, but this time one image per page.
+Images from the document are now displayed instead of the extracted text. That means there's no selectable text for any of the 4 documents this time. The table of contents on the right now displays a horizontal scroller containing thumbnails of each page. <Path>pdf06-weirdchars.pdf</Path> displays nicely now.</Text>
+</NumberedItem>
+</MajorVersion>
+<MajorVersion number="2">
+<NumberedItem>
+<Text id="ep-14"><b>Build</b> the collection and <b>preview</b>.All PDF documents (including pdf05-notext.pdf) have been processed and divided into sections, but each section displays <AutoText key="perlmodules::BaseImporter.dummy_text" type="quoted"/>. For the conversion to images for PDF documents, no text is extracted.</Text>
+</NumberedItem>
+<NumberedItem>
+<Text id="ep-15">In order to view the documents properly, you will need to modify the format statement. In the <AutoText key="glidict::CDM.GUI.Formats"/> section on the <AutoText key="glidict::GUI.Format"/> panel, select the <AutoText text="DocumentText"/> format statement. Replace </Text>
+<Format>
+[Text] 
+</Format>
+<Text id="ep-16">with</Text>
+<Format>
+[srcicon]
+</Format>
+</NumberedItem>
+<NumberedItem>
+<Text id="ep-18">Preview the collection. Images from the document are now displayed instead of the extracted text. Both <Path>pdf05-notext.pdf</Path> and <Path>pdf06-weirdchars.pdf</Path> display nicely now.</Text>
+<Comment>
+<Text id="ep-17">In this collection, we only have PDF documents and they have all been converted to images. If we had other document types in the collection, we should use a different format statement, such as:</Text>
+<Format>
+{If}{[parent:FileFormat] eq PDF,[srcicon],[Text]}
+</Format>
+<Text id="ep-17a"><AutoText text="FileFormat"/> is an extracted metadata item which shows the format of the source document. We can use this to test whether the documents are PDF or not: for PDF documents, display [srcicon], for other documents, display [Text].</Text>
+</Comment>
+</NumberedItem>
+</MajorVersion>
+<Heading>
+<Text id="ep-19">Using <AutoText text="process_exp"/> to control document processing (advanced)</Text>
+</Heading>
+<NumberedItem>
+<Text id="ep-20">Processing all of the PDF documents using an image type may not give the best result for your collection. The images will look nice, but as no text is extracted, searching the full text will not be available for these documents. The best solution would be to process most of the PDF files as HTML, and only use the image format where HTML doesn't work.</Text>
+</NumberedItem>
+<NumberedItem>
+<Text id="ep-21">We achieve this by putting the problem files into a separate folder, and adding another <AutoText text="PDFv2Plugin"/> plugin with different options.</Text> 
+</NumberedItem> 
+<NumberedItem>
+<Text id="ep-23">Go to the <AutoText key="glidict::GUI.Gather"/> panel. Make a new folder called <AutoText text="notext" type="quoted"/>: right click in the collection panel and select <AutoText key="glidict::CollectionPopupMenu.New_Folder"/> from the menu. Change the <AutoText key="glidict::NewFolderOrFilePrompt.Folder_Name"/> to <AutoText text="notext" type="quoted"/>, and click <AutoText key="glidict::General.OK" type="button"/>.</Text>
+<Text id="ep-23a">Move the two pdf files that have problems with html (<Path>pdf05-notext.pdf</Path> and <Path>pdf06-weirdchars</Path>.pdf) into this folder by drag and drop. We will set up the plugins so that PDF files in this <Path>notext</Path> folder are processed differently to the other PDF files.</Text>
+</NumberedItem>
+<NumberedItem>
+<Text id="ep-24">Switch to the <AutoText key="glidict::CDM.GUI.Plugins"/> section of the <AutoText key="glidict::GUI.Design"/> panel. Add a second instance of <AutoText text="PDFv2Plugin"/> by selecting <AutoText text="PDFv2Plugin"/> from the <AutoText key="glidict::CDM.PlugInManager.PlugIn"/> drop-down list, and clicking <AutoText key="glidict::CDM.PlugInManager.Add" type="button"/>. This plugin will come after the first PDFv2Plugin instance, so we configure it to process PDF documents as sectionalised HTML. Leave the <AutoText text="convert_to"/> option on <AutoText text="paged_pretty_html"/>, and switch on the <AutoText text="use_sections"/> option. Click <AutoText key="glidict::General.OK" type="button"/>.</Text>
+</NumberedItem>
+<NumberedItem>
+<Text id="ep-25">Configure the first PDF plugin, and set the <AutoText text="process_exp"/> option to <AutoText text="&quot;notext.*\.pdf&quot;"/>.</Text>
+</NumberedItem>
+<NumberedItem>
+<Text id="ep-26">The two PDF plugins should have options like the following:</Text>
+<Format>
+plugin PDFv2Plugin -convert_to pagedimg_jpg -process_exp "notext.*\.pdf"<br/>
+plugin PDFv2Plugin -convert_to paged_pretty_html
+</Format>
+<Text id="ep-27">The <AutoText text="paged_img" type="italics"/> version must come earlier in the list than the <AutoText text="html" type="italics"/> version. The <AutoText text="process_exp"/> for the first <AutoText text="PDFPlugin"/> will process any PDF files in the <Path>notext</Path> directory. The second <AutoText text="PDFPlugin"/> will process any PDF files that are not processed by the first one.</Text>
+<Text id="ep-28">Note that all plugins have the <AutoText text="process_exp"/> option, and this can be used to customize which documents are processed by which plugin.</Text>
+</NumberedItem>
+<MajorVersion number="2">
+<NumberedItem>
+<Text id="ep-30">Edit the <AutoText text="DocumentText"/> format statement. PDF files processed as HTML will not have images to display, so we need to make sure they get text displayed instead. Change <Format>[srcicon]</Format> to <Format>{If}{[NoText] eq "1",[srcicon],[Text]}</Format>.</Text>
+</NumberedItem>
+</MajorVersion>
+<NumberedItem>
+<Text id="ep-33">Build and preview the collection. All PDF documents should look relatively nice. Try searching this collection. You will be able to search for the PDFs that were converted to HTML (try e.g. <AutoText text="bibliography" type="quoted"/>), but not the ones that were converted to images (try searching for <AutoText text="FAO" type="quoted"/> or <AutoText text="METS" type="quoted"/>).</Text>
+</NumberedItem>
+<MajorVersion number="3">
+<Heading>
+<Text id="ep-sd-1">Customising the table of contents section heading display</Text>
+</Heading>
+<NumberedItem>
+<Text id="ep-sd-2">In the table of contents (on the right), a section number and section title are displayed by default. For documents like these where the section titles are the same as the section numbers, this doesn't make much sense, as you end up with headings like "1 1". We can hide the section number from the display by adding some CSS style information.</Text>
+</NumberedItem>
+<NumberedItem>
+<Text id="ep-sd-3">Click on the <AutoText text="display"/> format statement in the <AutoText key="glidict::CDM.GUI.Formats"/> list. Add the following to the start of the content:</Text>
+<Format>
+    &lt;gsf:template name="additionalHeaderContent-collection"&gt;<br/>
+    <Tab n="1"/>&lt;style&gt;span.tocSectionNumber { display: none; }&lt;/style&gt;<br/>
+  &lt;/gsf:template&gt;
+</Format>
+</NumberedItem>
+<NumberedItem>
+<Text id="ep-sd-4">Note that if you'd rather hide the title instead, you can use <AutoText type="italics" text="span.tocSectionTitle" /> in the above CSS code instead of <AutoText type="italics" text="span.tocSectionNumber" />.</Text>
+</NumberedItem>
+</MajorVersion>
+<Heading>
+<Text id="fw-24">Opening PDF files with query terms highlighted</Text>
+</Heading>
+<MajorVersion number="2">
+<NumberedItem>
+<Text id="fw-24a">Next we'll customize the <AutoText text="SearchVList"/> format statement to highlight the query terms in a PDF file when it is opened from the search result list. This requires Acrobat Reader 7.0 version or higher, and currently only works on a Microsoft Windows platform.</Text>
+</NumberedItem>
+<NumberedItem>
+<Text id="fw-24c">The search terms are kept in the macro variable <AutoText text="_queryterms_"/>, and we append <AutoText text="#search=&quot;_queryterms_&quot;"/> to the end of a PDF file link to pass the query terms to the PDF.</Text>
+<Text id="fw-24d"><AutoText text="PDFPlugin"/> saves each PDF file in a unique directory. You can use </Text>
+<Format>_httpcollection_/index/assoc/[archivedir]/[srclinkFile]</Format>
+<Text id="fw-24f">to refer to these files.</Text>
+</NumberedItem>
+<NumberedItem>
+<Text id="fw-24g">Add <AutoText text="SearchVList"/> by selecting <AutoText text="Search"/> from the <AutoText key="glidict::CDM.FormatManager.Feature"/> drop down list, and <AutoText text="VList"/> from the <AutoText key="glidict::CDM.FormatManager.Part"/> list. Click <AutoText key="glidict::CDM.FormatManager.Add" type="button"/> to add the <AutoText text="SearchVList"/> format statement into the list of assigned formats. We need to test whether the file is a PDF file before linking to it, using <Format>{If}{[ex.FileFormat] eq 'PDF',,}</Format>. For PDF files, we use the above path format instead of the <Format>[ex.srclink]</Format> and <Format>[ex./srclink]</Format> variables to link to the file.</Text>
+<Text id="fw-24b">The resulting format statement is:</Text>
+<Format>
+&lt;td valign="top"&gt;[link][icon][/link]&lt;/td&gt;<br/>
+&lt;td valign="top"&gt;<highlight>{If}{[ex.FileFormat] eq 'PDF', &lt;a
+href=\&quot;_httpcollection_/index/assoc/[archivedir]/[srclinkFile]#search=&amp;quot;_queryterms_&amp;quot;\&quot;&gt;{Or}{[ex.thumbicon],[ex.srcicon]}&lt;/a&gt;,<br/>[ex.srclink]{Or}{[ex.thumbicon],[ex.srcicon]}[ex./srclink]}</highlight>&lt;/td&gt;<br/>
+&lt;td valign="top"&gt;[highlight]<br/>
+{Or}{[dc.Title],[ex.Title],Untitled}<br/>
+[/highlight]{If}{[ex.Source],&lt;br&gt;&lt;i&gt;([ex.Source])&lt;/i&gt;}&lt;/td&gt;<br/>
+</Format>
+</NumberedItem>
+</MajorVersion>
+<MajorVersion number="3">
+<NumberedItem>
+<Text id="fw-24a-3">Next we'll customize the <AutoText text="search"/> format statement to highlight the query terms in a PDF file when it is opened from the search result list. This requires Acrobat Reader 7.0 version or higher, and currently only works on a Microsoft Windows platform.</Text>
+</NumberedItem>
+<NumberedItem>
+<Text id="fw-24c-3">To highlight the query terms in a PDF document, we need to pass them into the PDF file by appending <AutoText text="#search=&quot;query&quot;"/> to the end of the document link. We need to create the link ourselves rather than using &lt;gsf:link type=&quot;source&quot;/&gt; in the format statement. </Text>
+<Text id="fw-24d-3"><AutoText text="PDFPlugin"/> saves each PDF file in a unique directory for that document, and we can use</Text>
+<Format>&lt;gsf:metadata name=&quot;httpPath&quot; type=&quot;collection&quot;/&gt;/index/assoc/&lt;gsf:metadata name=&quot;archivedir&quot;/&gt;/&lt;gsf:metadata name=&quot;srclinkFile&quot;/&gt;</Format>
+<Text id="fw-24e-3">to refer to the PDF source file. 
+The search terms can be found in the &quot;q&quot; cgi parameter. You can access this using &lt;gsf:cgi-param name=&quot;q&quot;/&gt;.</Text>
+</NumberedItem>
+<NumberedItem>
+<Text id="fw-24g-3">Select <AutoText text="search"/> in <AutoText key="glidict::CDM.GUI.Formats"/> for editing. We need to test whether the file is a PDF file before linking to it, using a test on whether the Greenstone extracted FileFormat metadata is PDF. For PDF files, we now generate the link explicitly.</Text>
+<Text id="fw-24b-3">The resulting format statement is:</Text>
+<Format>
+  &lt;td valign=&quot;top&quot;&gt;<br/>
+    <Tab n="1"/>&lt;gsf:link type=&quot;document&quot;&gt;<br/>
+        <Tab n="2"/>&lt;gsf:icon type=&quot;document&quot;/&gt;<br/>
+    <Tab n="1"/>&lt;/gsf:link&gt;<br/>
+  &lt;&#47;td&gt;<br/>
+  <br />
+  &lt;td valign=&quot;top&quot;&gt;<br/>
+  <highlight>
+  &lt;gsf:switch&gt;<br/>
+	<Tab n="1"/>&lt;gsf:metadata name=&quot;FileFormat&quot;/&gt;<br/>
+	<Tab n="1"/>&lt;gsf:when test=&quot;equals&quot; test-value=&quot;PDF&quot;&gt;<br/>
+		<Tab n="2"/>&lt;a&gt;&lt;xsl:attribute name=&quot;href&quot;&gt;&lt;gsf:metadata name=&quot;httpPath&quot; type=&quot;collection&quot;/&gt;/index/assoc/&lt;gsf:metadata name=&quot;archivedir&quot;/&gt;/&lt;gsf:metadata name=&quot;srclinkFile&quot;/&gt;#search=&amp;amp;quot;&lt;gsf:cgi-param name=&quot;query&quot;/&gt;&amp;amp;quot;&lt;/xsl:attribute&gt;<br/>
+			<Tab n="3"/>&lt;gsf:choose-metadata&gt;<br/>
+				<Tab n="4"/>&lt;gsf:metadata name=&quot;thumbicon&quot;/&gt;<br/>
+				<Tab n="4"/>&lt;gsf:metadata name=&quot;srcicon&quot;/&gt;<br/>
+			<Tab n="3"/>&lt;/gsf:choose-metadata&gt;<br/>
+		<Tab n="2"/>&lt;/a&gt;<br/>
+	<Tab n="1"/>&lt;/gsf:when&gt;<br/>
+	<Tab n="1"/>&lt;gsf:otherwise&gt;<br/>
+		<Tab n="2"/>&lt;gsf:link type=&quot;source&quot;&gt;<br/>
+			<Tab n="3"/>&lt;gsf:choose-metadata&gt;<br/>
+				<Tab n="4"/>&lt;gsf:metadata name=&quot;thumbicon&quot;/&gt;<br/>
+				<Tab n="4"/>&lt;gsf:metadata name=&quot;srcicon&quot;/&gt;<br/>
+			<Tab n="3"/>&lt;/gsf:choose-metadata&gt;<br/>
+		<Tab n="2"/>&lt;/gsf:link&gt;<br/>
+	<Tab n="1"/>&lt;/gsf:otherwise&gt;<br/>
+  &lt;/gsf:switch&gt;</highlight><br/>	
+  &lt;&#47;td&gt;<br/>
+  <br />
+&lt;td valign=&quot;top&quot;&gt;<br/>
+...
+</Format>
+</NumberedItem>
+</MajorVersion>
 <Text id="fw-24i">When the PDF icons are clicked in the search results, Acrobat will open the file with the search window open with the query terms highlighted.</Text>
 </Content>
