tags:

views:

209

answers:

3

I am using tag of coldfusion 7. Using CFEclipse and working on Mac OS. I have written the following code:

<cfdocument format="pdf">
 SitePoint.com - Introduction to ColdFusion 7
 PDF Generation
 This is an example of PDF generation using ColdFusion 7.
</cfdocument>

But instead of asking me to save this file in .pdf format, its trying to open it in .cfm format. Please tell me how can I save it in .pdf format. Thanks!!

+5  A: 

Unless you tell it otherwise, the webserver returns the results of a CFM call as text. You need to use CFContent with CFHeader to alert the browser that the results it will be recieving are of a different type. Something like:

<cfheader name="Content-Disposition" value="inline; filename=document.pdf"> 
<cfcontent type="application/x-pdf"> 
<cfdocument>...</cfdocument>

I may have the MIME type wrong there. I'm doing this from memory. Check the docs for more help.

Ben Doom
+3  A: 

If you are on CF8 or higher then use the saveAsName attribute:

<cfdocument saveAsName=""

Either that or the method suggested by Ben above should work

Sam Farmer
Nice tip. I didn't know about that. I should really pay more attention to changelogs. :-)
Ben Doom
A: 

Try:

<cfdocument format="PDF" name="myPDF">
 <html>
  <body>
   SitePoint.com - Introduction to ColdFusion 7
   PDF Generation
   This is an example of PDF generation using ColdFusion 7.
  </body>
 </html>
</cfdocument>

<cfpdf action = "write" destination = "pdf_path" source = "myPDF" overwrite = "yes"/>

<cflocation url="pdf_path"/>

Whis this you save the PDF on disk

Alain