How to fit a PDF to page size in Coldfusion

I currently save web pages that are PDFs as flyers for my clients, but depending on the content they input they can run long, and it saves the PDF in coldfusion on two pages. I have to manually put the scale in as a variable in cfdocument. Is there a way it can automatically fit the page of a PDF, maybe it calculates the percentage or something?

Code I'm using now:

   backgroundvisible = "yes"
   encryption = "none"
   marginbottom = "0"
   marginleft = "0"
   marginright = "0"
   margintop = "0"
   format = "pdf"
   fontembed = "yes"
   mimetype = "text/xml"
   orientation = "portrait"
   pagetype = "#Userinfo.PDFpapersize#"
   unit = "in">
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I don't think it's possible in a single step. But this thread suggests an interesting approach to the problem.  Basically generate the pdf. Then examine the file's properties. If the number of pages is more than one, reduce the scale by -5 and regenerate the pdf.  Loop/repeat until it fits within the desired number of pages.

<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" />

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
monosythAuthor Commented:
Hmm, that looks like it would work, but when tested it throws an error, and even when I just use that example. Error is: ByteArray objects cannot be converted to strings.

Any help?
Looks like there's a typo in the example.  Source should be a variable name, without the pound signs

ie This <cfpdf action="getInfo" source="pdfObj" name="pdfInfo" />
Not this: <cfpdf action="getInfo" source="#pdfObj#" name="pdfInfo" />
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.