Generating thumbnail images from PDF pages

Use the thumbnail action to generate thumbnail images from PDF pages. If you specify only the source attribute with the thumbnail action, ColdFusion automatically creates a directory relative to the CFM page called thumbnails where it stores a generated JPEG image for each page in the document. The filenames are in the following format:

PDFdocumentName_page_n.JPG

For example, assume that the source file in the following example has 100 pages:

<cfpdf action="thumbnail" source="myBook.pdf">

ColdFusion generates the following files and stores them in the thumbnails directory:

myBook_page_1.jpg 
myBook_page_2.jpg 
myBook_page_3.jpg 
... 
myBook_page_100.jpg

If you specify a destination, ColdFusion does not create the thumbnails directory and stores the files in the specified directory instead. The following code generates a thumbnail image called myBook_page_1.jpg from the first page of myBook.pdf and stores it in a directory called images, which is relative to the CFM page:

<cfpdf action="thumbnail" source="myBook.pdf" pages="1" destination="images">

You change the prefix for the thumbnail filename and the change image file format to PNG or TIFF by specifying the imagePrefix and format attributes. The following code generates a file called TOC_page_2.PNG from the second page of myBook.pdf:

<cfpdf action="thumbnail" source="myBook.pdf" pages="2" imagePrefix="TOC" format="PNG" 
    destination="images">

The following code generates thumbnails from a range of pages and changes the image background to transparent (the default is opaque):

<cfpdf action="thumbnail" source="myBook.pdf" pages="1-10,15,8-16,59" transparent="yes" 
    destination="\myBook\subset" imagePrefix="abridged">

For an example of how to generate thumbnail images and link them to pages in the source PDF document, see the cfpdf tag in the CFML Reference.

ColdFusion 9 release has introduced some new attributes for the thumbnail action:

  • hires: You can set this attribute to true to extract high resolution images from the page. If a document contains high resolution images and you want to retain the resolution of the images, then this attribute is useful.

    For example:

    <cfpdf action="thumbnail" source="./WORK/myBook.pdf" destination="./WORK/Testing_CFPDF" overwrite="true" hires="yes">
  • overridepage: If you set this attribute to true, the thumbnail generated does not adhere to the PDF page size, but to the image size that is present in that page. If the image is not present, the size is set to the maximum size of the page.

  • compresstiffs: Use this attribute to compress the size of the thumbnail images. As the name of the attribute suggests, it is only valid for the TIFF format. Following is an example:

    <cfpdf action="thumbnail" source="C:\WORK\myBook.pdf" destination="C:\WORK\Testing_CFPDF" overwrite="true" hires="yes" format="tiff" compresstiffs="yes"> 
  • maxscale : Use this attribute to specify an integer value for the maximum scale of the thumbnail images.

  • maxlength: Use this attribute to specify an integer value of the maximum length of the thumbnail images.

  • maxbreadth: Use this attribute to specify an integer value of the maximum width of the thumbnail.

    The following example illustrates the use of maxscale, maxlength, and maxbreadth:

    <cfpdf action="thumbnail" source="./WORK/myBook.pdf" destination="./WORK/Testing_CFPDF" overwrite="true" format="jpg" maxscale="3" maxlength="300" maxbreadth="200" hires="yes" scale="100">
    Note: Typically, the value of the scale attribute is set to ‘100’ when using the maxscale attribute.