Coldfusion cfpdf 缩略图加预览?
我们的网站上有大量 PDF 内容。我有一些从每个 PDF 的第 1 页生成的完全可用的 CFPDF 缩略图。我认为将缩略图 jpg 作为一个链接会很好,这样当您单击它时,您要么按原样看到第一页,要么生成另一个全尺寸预览。
我正在尝试使用 CFPDF 的合并操作,但到目前为止运气不佳。似乎没有办法只从 PDF 中提取单个页面——只能删除它们。
有人有什么建议吗?我真的很感激!谢谢!
更新:为了尝试澄清,这是我现在正在使用的代码。抱歉造成混乱!
<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>
无论如何,我希望这能更好地解释我正在尝试做的事情。就像我说的,这可行,但firstPage.pdf 始终只是一个文件 - 例如,如果几个人同时预览不同的 PDF,会发生什么情况?
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
(如果我正确理解了这个问题......)
当然你可以使用合并来提取单个页面:
编辑:其中一些最终会预览错误页面和/或缩略图;)为避免这种情况,您必须每次生成一个唯一的文件名,例如使用<一href="http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7c60.html" rel="nofollow">getTempFile(), createUUID() &".pdf",等等。
尽管从技术上讲您不必创建文件。您可以仅在内存中生成图像/pdf,并通过 cfcontent 提供它们(如上面的示例所示)。
(If I am understanding the question correctly ...)
Sure you can use merge to extract a single page:
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).
非常简单
,将第一页变成 jpg
Its very easy
That will turn page one into a jpg