I would like to turn the HTML generated by my CFM page into a PDF, and have the user prompted with the standard ‘Save As’ prompt when navigating to my page.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You should use the cfdocument tag (with format=’PDF’) to generate the PDF by placing it around the page you are generating. You’ll want to specify a filename attribute, otherwise the document will just stream right to your browser.
After you have saved the content as a PDF, use cfheader and cfcontent in combination to output the PDF as an attachment (‘Save As’) and add the file to the response stream. I also added deletefile=’Yes’ on the cfcontent tag to keep the file system clean of the files.
As an aside: I’m just using file.pdf for the filename in the example below, but you might want to use some random or session generated string for the filename to avoid problems resulting from race conditions.