缩放PDF到单页 [英] scale PDF to single page

查看:110
本文介绍了缩放PDF到单页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个简单的方法使用CF8将由cfdocument或cfpdf创建的pdf缩放到单个页面?我的输出(日历)可能扩展到第2页,具体取决于事件数。我宁愿缩放日历,以适应它在一个页面。我假设我可以创建pdf与cfdocument。

Is there a simple way to scale the pdf created by cfdocument or cfpdf to a single page using CF8? My output (a calendar) could possibly extend to page 2 depending on the number of events. I'd rather scale the calendar to fit it in one page. I assume I can create the pdf with cfdocument. Use cfpdf to check the page numbers and loop while totalPages > 1 create the PDF with a lesser scale.

psudo代码:

pdfScale = 100
cfdocument scale = "#pdfScale#"
cfpdf action = "getinfo" name = "mypdf" 
cfloop while mypdf.totalPages > 1
pdfScale = pdfScale -5
cfdocument scale = "#pdfScale#"
cfpdf action = "getinfo" name = "mypdf"
/cfloop

我在正确的轨道上,或者我错过了一些东西,使这更容易吗?谢谢。

Am I on the right track or am I missing something to make this easier? Thanks.

推荐答案

你的理论似乎听起来很棒 - 你应该试试看。由于这是一个相当无聊的答案,我还将你的伪码转换为真正的代码:

Your theory seems sound to me - you should try it and find out. Since that's a rather boring answer, I've also converted your pseudocode to real code:

<cfset pdfScale = 100 />
<cfset pdfObj = "" />
<cfdocument format="pdf" name="pdfObj" scale="#pdfScale#">document contents</cfdocument>
<cfpdf action="getInfo" source="#pdfObj#" name="pdfInfo" />
<cfloop condition = "pdfInfo.TotalPages gt 1">
    <cfset pdfScale -= 5 />
    <cfdocument format="pdf" name="pdfObj" scale="#pdfScale#">document contents</cfdocument>
    <cfpdf action="getInfo" source="#pdfObj#" name="pdfInfo" />
</cfloop>

根据您的设置,您可能还想将PDF的创建抽象成函数,您不必在页面上重写所有内容两次。或者你可以使用包含。 heck,如果有任何形式的复杂的处理过程来渲染PDF的HTML(我假设有,因为你是一个日历),那么你可能甚至想预渲染内容和重用如下:

Depending on your setup, you might also want to abstract the creation of the PDF into a function, so that you don't have to re-write all of the content twice on the page. Or you could use an include. Heck, if there is any sort of complex processing going on to render the HTML for the PDF (which I assume there is, since you're making a calendar), then you might even want to pre-render the content and re-use it, like so:

<cfsavecontent variable="docContents">document contents go here</cfsavecontent>
<cfset pdfScale = 100 />
<cfset pdfObj = "" />
<cfdocument format="pdf" name="pdfObj" scale="#pdfScale#"><cfoutput>#docContents#</cfoutput></cfdocument>
<cfpdf action="getInfo" source="#pdfObj#" name="pdfInfo" />
<cfloop condition = "pdfInfo.TotalPages gt 1">
    <cfset pdfScale -= 5 />
    <cfdocument format="pdf" name="pdfObj" scale="#pdfScale#"><cfoutput>#docContents#</cfoutput></cfdocument>
    <cfpdf action="getInfo" source="pdfObj" name="pdfInfo" />
</cfloop>

这篇关于缩放PDF到单页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆