Description of the Multipage TIFF demo

There are two scripts used in this demo. "tifdemo.cfm" is the HTML page that controls the navigation and acts as a placeholder for the image. "showtif.cfm" loads the image and streams it to the browser.


Most of the scripting code is at the start of the page where it finds the number of pages and sets some variables:

<cfcache action="flush">
<cfobject action="create" name="Image" class="csImageFile64Trial.Manage">
<cfset TIF = "multipage.tif">
<cfset TIFPath=ExpandPath(TIF)>
<cfset PageCount = Image.ImageCount(TIFPath)>
<cfparam name="Url.Page" default="1">

<cfset CurrentPage = Url.Page>
<cfif NOT IsNumeric(CurrentPage)>
  <cfset CurrentPage = 1>
  <cfif CurrentPage LT 1>
    <cfset CurrentPage = 1>
  <cfif CurrentPage GT PageCount>
    <cfset CurrentPage = PageCount>

<cfset Previous = CurrentPage - 1>
<cfset Next = CurrentPage + 1>

This code assumes the 64 bit trial version of csImageFile is used.

The ImageCount method in csImageFile is used to read the number of pages in the TIFF. It needs the physical path to the file, which is found from the relative path using ExpandPath. The rest of the code sets the CurrentPage variable by reading the URL variable that is passed by the links later in the page. If the URL variable is an empty string, not a number or outside the range of valid numbers, the CurrentPage variable is set accordingly.

The next working part of the script is in the body of the page. The formatting has been kept to a minimum and there is no attempt to hide invalid links, such as the Previous link when the first page is displayed. The listing does not show the line breaks.

Page Number: <cfoutput>#CurrentPage#</cfoutput> of <cfoutput>#PageCount#</cfoutput>
<a href="tifdemo.cfm?Page=1">First</a>
<a href="tifdemo.cfm?Page=<cfoutput>#Previous#</cfoutput>">Previous</a>
<a href="tifdemo.cfm?Page=<cfoutput>#Next#</cfoutput>">Next</a>
<a href="tifdemo.cfm?Page=<cfoutput>#PageCount#</cfoutput>">Last</a>
<img src="showtif.cfm?Page=<cfoutput>#CurrentPage#</cfoutput>&Path=<cfoutput>#TIF#</cfoutput>">

The current page and the relative path to the TIFF are passed to the image generation script as URL parameters.


This code reads the URL parameters passed from "tifdemo.cfm". It sets the ReadImageNumber property and then loads the file. Only the page specified by ReadImageNumber is loaded. The image is streamed to the browser in PNG format using the PageContext object, which takes up most of the code in this script. The PNG format is used because most browsers do not support TIFF and it will support the same colour depth as the TIFF image.

<cfcache action="flush">
<cfobject action="create" name="Image" class="csImageFile64Trial.Manage">
  Image.ReadImageNumber = Url.Page;
  Context = GetPageContext();
  Response = Context.GetResponse().GetResponse();
  Out = Response.GetOutputStream();

Click Here to return to the demo.