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

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

问题描述

有没有一种简单的方法可以使用 CF8 将由 cfdocument 或 cfpdf 创建的 pdf 缩放到单个页面?根据事件的数量,我的输出(日历)可能会扩展到第 2 页.我宁愿缩放日历以适应一页.我假设我可以使用 cfdocument 创建 pdf.使用 cfpdf 检查页码并循环,而 totalPages > 1 创建比例较小的 PDF.

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.

伪代码:

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 的创建抽象为一个函数,这样您就不必在页面上重新编写所有内容两次.或者您可以使用包含.哎呀,如果正在进行任何复杂的处理来呈现 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天全站免登陆