Posted in ColdFusion | Posted on 07-30-2007 | 8,472 views
Time for the last entry concerning the <CFPDF> tag. This isn't the end of the series - just the last post I'll be writing about the tag. After this we move on to PDFs and Forms which should be pretty darn exciting as well.
Today's entry involves the thumbnails feature of <CFPDF>. I talked about this in the past when I created my getThumbnail UDF. This UDF used the feature that I'll be discussing today.
Let's start by talking about how the thumbnails work. ColdFusion provides you with the following main options for thumbnails:
- For formats - you can use TIFF, JPEG, or PNEG
- You have two resolution options - low and high. This is a bit surprising since most other image related options give you more finer control, but hey, sometimes simpler is better.
- You can scale the image from 1 to 100% of the PDF size.
- You can specify which page to generate thumbnails from. My getThumbnails UDF simply used the first page.
Along with these options, you have a few other settings as well I'll discuss later. Let's look at a simple example:
2<cfif not directoryExists(dir)>
3 <cfdirectory action="create" directory="#dir#">
4</cfif>
5
6<cfdocument format="pdf" name="mypdf">
7<h1>Top 10 Reasons why ColdFusion 8 Kicks Rear</h1>
8
9<p>
1010. Ajax UI controls make my design suck less.<br />
119. 500% faster. Seriously - 500% faster. That's like... fast.<br />
128. <cfajaxproxy> - Couldn't Adobe make Ajax easier? No.<br />
137. Debugging. Not that CF developers make mistakes.<br />
146. No more d*** custom MySQL drivers.<br />
155. PDF toolset that makes PDF sexy. And that's saying a lot.<br />
164. Interaces. Yeah, I said Interfaces. Whooyah.<br />
173. Server Monitor - and it's all Flex.<br />
182. Server Monitor API - in case you don't want it all Flex.<br />
191. It's not Dot Net.<br />
20</p>
21</cfdocument>
22
23<cfpdf action="thumbnail" source="mypdf" destination="#dir#" resolution="high" scale="50" overwrite="true">
Most of the code isn't terribly relevant to thumbnails. I start off creating a thumbs folder if it doesn't exist. Then a PDF document variable is created. (Go ahead. Read. Laugh. I'm going to make a tee shirt I think.) The critical line is the last one. I specify the thumbnail action for my CFPDF tag. The source is the PDF I created in memory earlier. CFPDF needs to know where to store it - so I pass in the "dir" folder I created earlier. I used a high resolution and a scale of 50 and lastly set overwrite to true. That generated this graphic (note I cropped the image a bit):
![]()
Let me point out something. The name of this file is thumbnail_page_1.jpg. Where did this name come from? ColdFusion automatically uses a name of the format:
prefix_page_N.TYPE
You can overwrite the prefix by suppling the imagePrefix attribute. If you used ray, for example, you would end up with images named ray_page_1.jpg, ray_page_2.jpg, etc. If you leave imagePrefix blank, it defaults to thumbnail, unless your source is a PDF file. In that case the filename is used instead. Consider this modification to the previous example:
This will generate file names like: t_page_1.jpg, t_page_2.jpg, etc.
So what's cool about this? You can provide image previews of PDFs before users download them. You could even wrap a link to a PDF with a <cftooltip> tag that shows the image as a tool tip. As an example:
2<a href="mypdf.pdf">My PDF</a>
3</cftooltip>


May you can help me
1 auto print pdf by user don't click printer icon
2 how to use parmision for print copy (i try permision auttibue some time but don't work)
2) Yes, you can use CFPDF to set permissions on a PDF, including the ability to print.
http://princeoflightning.blogspot.com/2006/01/sile...
<cfpdf action = "thumbnail"
source="#application.basedirectory#/pdfs/#ArticleDetails.FileName#"
destination = "#application.basedirectory#/thumbnails/"
format = "jpeg"
imagePrefix = "thumbnail_#whicharticle#"
overwrite = "yes"
pages = "1" >
In the current application I'm creating, I tried using cfdocument to create a PDF of any file type (word, ppt, excel etc). Your solution seems to work only for PDFs and URLs. The thumbnail generated for images,word etc was hazy.
Do you have a solution to create thumbnails for any file format?
thanks in advance!
John
I started messing with pdf and cfdocument and came across these blogs. Awesome job Ray.
I noticed that when I started using cfpdf and throwing the output threw cfcontent that the saveAsName attribute in cfdocument becomes worthless and that instead had to revert back to putting the name back to cfheader.
Btw, miss the meetings up at langley with the user group. Glad to see you are making it big time.
Love the PDF articles... Thanks!
Now, I was wondering if there is any way to make higher resolution JPG images from a PDF? I am using scale="100" and resolution="high" but the images are just not quite high enough rez for what I need.
Is it possible?
Also, what IS the file size going to be at scale="100" in pixles... will it always be the same max width or height no matter what PDF you use? Or is it relative to the pagesize of the PDF file you use?
One more thing... I am seeing some pretty serious color swings when using CMYK PDF files. Is the only way around this to create an RGB version of the PDF file?
Thanks again mate!
Size: Honestly don't quite get you there. I believe it is the same size as the page.
Color: Definitely no idea on that one.
I have the same problem as Sam. The thumbnails created from CMYK PDF files are very dark and very contrasty. There is no problem when I create thumbnails of RGB PDF file.
Using what is above, I put:
<cfpdf action="thumbnail" source="orgchart" resolution="high" scale="100" overwrite="true" format="png" hires="yes">
<cflocation url="thumbnails/slide_image.cfm" addtoken="no">
at the bottom of the cfdocument page and for slide_image.cfm
it's just a simple cfm page with:
<body>
<img src="thumbnail_page_1.png" alt="this is the png file, if you can't see it your browser doesn't support png files." />
</body>
So, a link on a page takes you to the page that generates the PDF, then the thumbnail and then immediately takes you to another page with the image. This is so that users could have a high quality image of the dynamic PDF in question to use in a PowerPoint slide show.
[Add Comment] [Subscribe to Comments]