Link to home
Start Free TrialLog in
Avatar of Plucka
PluckaFlag for Australia

asked on

Optionally use <cfdocument

I have a page and want to optionally render it as a PDF.

so I have something like.

<cfif isDefined("url.format")>
    <cfdocument format="pdf">
</cfif>

and at the end

<cfif isDefined("url.format")>
    </cfdocument>
</cfif>

Get error.

The end tag </cfdocument> encoutered on line 72 at column 11 requires a matching start tag.
ASKER CERTIFIED SOLUTION
Avatar of andw928
andw928

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of andw928
andw928

Basically, this is only possible with php, but not coldfusion. You can do this though:

<cfif isdefined('url.format')>
    <cfdocument format='pdf'>
        ...
    </cfdocument>
</cfif>

I already talked to Ben Forta about being able to do this with cfscript, what you mentioned, and he said they are looking into it for the next Coldfusion version.
Here you can find his and my comment on this exact same thing only in <cfscript> on this page: http://forta.com/blog/index.cfm?mode=e&entry=1670

It is not possible with coldfusion.
Avatar of Plucka

ASKER

andw928,

They could at least put a html format on cfdocument then you could always have one <cfdocument format="#formatVar#"> and have formatVar default to html.

Regards
Plucka
What do you mean Plucka? lol. I like your username.
Avatar of Plucka

ASKER

well if I could just have a <cfdocument at the start of the page and pass it a paramater for page type of html or pdf.

<cfparam name="url.format" default="html" />

<cfdocument format="#url.format#">
   ALL MY HTML IN HERE
</cfdocument>

so by default it renders as html, but passing a format=pdf on the url would make it pdf!
Avatar of pinaldave
plucka ...
you seems have to have figured out yourself... or do you need any more help?
Plucka, I don't understand, what is <cfdocument format="html">? That format doesn't exist, the only acceptable <cfdocument> formats are pdf and flashpaper. Basically, you would want to pass it as pdf by default, but if a user specifies it as flashpaper, then generate a flash paper document.

<cfparam name="url.default" default="pdf">

<cfif url.default is not "pdf">
    <cfset url.default = "flashpaper">
</cfif>

<cfoutput>
    <cfdocument format="#url.default#">
        <!--- enter html content in this area --->
    </cfdocument>
</cfoutput>

Basically the above code is setting the <cfdocument> default to pdf, otherwise, if something else is specified in the url then it is setting it as flashpaper.

And finally, you cannot do something like this, just to make things clear:

<cfif isDefined("url.format")>
    </cfdocument>
</cfif>

That is not allowed in Coldfusion langauge.
To summarize, the "html" attribute value for format is not an acceptable value. The only values acceptable are pdf and flashpaper. Here's some stuff on <cfdocument>, just incase you missed it:

http://livedocs.macromedia.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=ColdFusion_Documentation&file=00000236.htm
Avatar of Plucka

ASKER

That's the problem there is no html attributes, that's the bit that would make things easier.
Well what would you want the html attribute to display? Just plain html? Do this then:

<cfif url.default is "pdf">
    <cfset url.default = "pdf">
<cfelseif url.default is "flashpaper">
    <cfset url.default = "flashpaper">
<cfelse>
    <cfset url.default = "html">
</cfif>

<cfif url.default is "html">
    <!--- ordinary html would be displayed here --->
    <h1>Hello World</h1>
<cfelse>
    <cfdocument format="#url.default#">
        <!--- if html is not selected --->
        <!--- display html in pdf or flashpaper --->
        <h1>Hello World</h1>
    </cfdocument>
</cfif>
You can still display HTML inside a pdf or flashpaper.
Avatar of Plucka

ASKER

Yeah, but without the if's I could just have it on every page, <cfdocument type="#blah#">

and not have to worry about embedding the if's
I hope they do change it by CF 8, but probably will not, Macromedia focuses on making this easy rather than on adding advanced features. I am sure php can do that, I've seen it done many times.