Wednesday, June 27, 2007

Thumbnail images

The following example generates thumbnail images from pages in a PDF document and links the thumbnail images to the pages in the PDF document:
 
<h3>PDF Thumbnail Demo</h3>
 
<!--- Create a variable for the name of the PDF document. --->
<cfset mypdf="myBook">
<cfset thisPath=ExpandPath(".")>
 
<!--- Use the getInfo action to retrieve the total page count for the PDF document. --->
<cfpdf action="getInfo" source="#mypdf#.pdf" name="PDFInfo">
<cfset pageCount="#PDFInfo.TotalPages#">
 
<!--- Generate a thumbnail image for each page in the PDF source document,
create a directory (if it doesn't already exist) in the web root that is a concatenation of the
PDF source name and the word "thumbnails", and save the thumbnail images in that directory. --->
<cfpdf action="thumbnail" source="#mypdf#.pdf" overwrite="yes" destination="#mypdf#_thumbnails" scale=60>
 
<!--- Loop through the images in the thumbnail directory and generate a link from
each image to the corresponding page in the PDF document. --->
<cfloop index="LoopCount" from ="1" to="#pageCount#" step="1">
 <cfoutput>
  <!--- Click the thumbnail image to navigate to the page in the PDF document. --->
  <a href="#mypdf#.pdf##page=#LoopCount#" target="_blank">  <img src="#mypdf#_thumbnails/#mypdf#_page_#LoopCount#.jpg"></a>
 </cfoutput>
</cfloop>
 

2 comments:

www.tuweb.biz said...

Pretty helpful piece of writing, thanks so much for your post.

Martin said...

Same problem here...anyone with a workaround please?