开发者

How to generate PDF from .cfm page in Mac

开发者 https://www.devze.com 2022-12-20 12:57 出处:网络
I am us开发者_JS百科ing <cfdocument> tag of coldfusion 7. Using CFEclipse and working on MacOS.

I am us开发者_JS百科ing <cfdocument> tag of coldfusion 7. Using CFEclipse and working on MacOS. 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. How can I save it in .pdf format? Thanks!


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.


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


You might also need to import the style sheet as well. So you can get the desired formatting. It needs to be imported after cfdocument.

 <cfdocument 
 format="pdf" 
 filename = "canwriteurfile.pdf"
 overwrite = "yes"
 marginBottom = ".2"
 marginLeft = ".4"
 marginRight = ".4"
 marginTop = ".2">

 <style type="text/css">@import "pdf.css";</style>

  BLAHHH BLAHHH PDF FORMATTING STUFF

 </cfdocument>


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号