Clicky

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:

<cfdocument
   backgroundvisible = "yes"
   encryption = "none"
   marginbottom = "0"
   marginleft = "0"
   marginright = "0"
   margintop = "0"
   format = "pdf"
   fontembed = "yes"
   filename="C:\inetpub\myserver\pdftemp\#Username#_#pdfID#.pdf"
   overwrite="yes"
   scale="#myPDFscale#"
   mimetype = "text/xml"
   orientation = "portrait"
   pagetype = "#Userinfo.PDFpapersize#"
   unit = "in">

asked 12/06/2011 04:50

monosyth's gravatar image

monosyth ♦♦


3 Answers:
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.

From http://stackoverflow.com/questions/3689219/scale-pdf-to-single-page/3691240#3691240
<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>
link

answered

_agx_'s gravatar image

_agx_

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?
link

answered 2011-12-06 at 13:11:35

monosyth's gravatar image

monosyth

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

answered 2011-12-06 at 13:31:33

_agx_'s gravatar image

_agx_

Your answer
[hide preview]

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

×1
×32
×44

Asked: 12/06/2011 04:50

Seen: 240 times

Last updated: 12/06/2011 06:34