we have a great deal of PDF content on our site. I have some perfectly usable CFPDF thumbnails generated from Page 1 of each PDF. I thought it would be nice to have the thumbnail jpg be a link such that when you click it, you either see the first page as is, or another preview at full scale is generated.
I am experimenting with using CFPDF's merge action, but without much luck so far. There does not seem to be a way to just extract a single page from the PDF -- only delete them.
Does anybody have any suggestions? I really do appreciate it! Thanks!
UPDATE: to try and clarify, here's the code I am using right now. Sorry for the confusion!
<cfset dir = expandPath("\images\thumbs")>
<cfif not directoryExists(dir)>
<cfdirectory action="create" directory="#dir#">
</cfif>
<cfset firstPage = expandPath("\images\thumbs\firstPage.pdf")>
<cfpdf action="thumbnail"
source="source"
destination="#dir#"
format="jpg"
scale="40"
overwrite="yes"
pages="1"
resolution="low">
<cfpdf action="merge"
source="sameSource"
pages="1"
destination="#firstPage#"
overwrite="yes">
<a href="firstPage.pdf" target="_blank">
<img src="thumbnail.jpg" style="border: 1px solid silver;">
</a>
Anyways I hope that explains better what I am trying to do. Like I said, this works, but firstPage.pdf is always just the one file -- what happens if several people are previewing different PDFs at the same time, for example?
Thanks!
(If I am understanding the question correctly ...)
Sure you can use merge to extract a single page:
<cfpdf action = "merge"
source="c:\dev\myFile.pdf"
pages="10"
name="singlePage" />
<cfcontent type="application/pdf" variable="#ToBinary(singlePage)#">
what happens if several people are previewing different PDFs at the same time, for example?
Edit: Some of them will end up previewing the wrong page and/or thumbnail image ;) To avoid that, you must generate a unique file name each time, such as using getTempFile(), createUUID() &".pdf", etcetera.
Though technically you do not have to create a file. You can generate images/pdfs in memory only and serve them with cfcontent (like in the example above).