<p>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.</p>

[{'answer_id': 73982, 'author': 'Frank Wiles', 'author_id': 12568, 'author_profile': 'https://Stackoverflow.com/users/12568', 'pm_score': 1, 'selected': False, 'text': "<p>I'm not that familiar with ColdFusion, but what you need to do is set the Content-Type of the page when the user requests it to be application/octet-stream. This will prompt them for a download every time. </p>\n\n<p>Hope this helps!</p>\n"}, {'answer_id': 74374, 'author': 'Soldarnal', 'author_id': 3420, 'author_profile': 'https://Stackoverflow.com/users/3420', 'pm_score': 5, 'selected': True, 'text': '<p>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.</p>\n\n<p>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.</p>\n\n<pre><code>&lt;cfdocument format="PDF" filename="file.pdf" overwrite="Yes"&gt;\n&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&gt;\n&lt;html&gt;\n&lt;head&gt;\n    &lt;title&gt;Hello World&lt;/title&gt;\n&lt;/head&gt;\n&lt;body&gt;\n    Hello World\n&lt;/body&gt;\n&lt;/html&gt;\n&lt;/cfdocument&gt;\n&lt;cfheader name="Content-Disposition" value="attachment;filename=file.pdf"&gt;\n&lt;cfcontent type="application/octet-stream" file="#expandPath(\'.\')#\\file.pdf" deletefile="Yes"&gt;\n</code></pre>\n\n<p>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.</p>\n'}, {'answer_id': 75118, 'author': 'Ben Doom', 'author_id': 12267, 'author_profile': 'https://Stackoverflow.com/users/12267', 'pm_score': 2, 'selected': False, 'text': "<p>If you want to avoid storing the PDF at all, using cfdocument without a filename will send the pdf (of flashpaper) directly to the browser without using the cfheader and cfcontent.</p>\n\n<p>Caveat:  Like with using cfheader/cfcontent, you need to do this before the cache gets flushed to the browser, since it's basically doing the same thing without having to store the file.</p>\n\n<p>To get the content, I would probably use cfsavecontent wrapped around the same calls/includes/etc. that generate the page, with two major exceptions.  cfdocument seems to have issues with external stylesheets, so using an include to put the styles directly into the document is probably a good idea.  You can try using an @import instead -- it works for some people.  Also, I'd be careful about relative links to images, as they can sometimes break.  </p>\n"}, {'answer_id': 88297, 'author': 'Andy Waschick', 'author_id': 6000, 'author_profile': 'https://Stackoverflow.com/users/6000', 'pm_score': 2, 'selected': False, 'text': '<p>The <code>&lt;cfdocument&gt;</code> approach is the sanctioned way to get it done, however it does not offer everything possible in the way of manipulating existing PDF documents.  I had a project where I needed to generate coupons based using a pre-designed, print-resolution PDF template.  <code>&lt;cfdocument&gt;</code> would have let me approximate the output, but only with bitmap images embedded in HTML.  True, I could fake print-resolution by making a large image and scaling it in HTML, but the original was a nice, clean, vector-image file and I wanted to use that instead. </p>\n\n<p>I ended up using a copy of <code>&lt;cfx_pdf&gt;</code> to get the job done.  (<a href="http://www.easel2.com/" rel="nofollow noreferrer">Developer\'s Site</a>, <a href="http://www.cftagstore.com/tags/cfxpdf.cfm" rel="nofollow noreferrer">CF Tag Store</a>)  It\'s a CF wrapper around a Java PDF library that lets you manipulate existing PDF documents, including filling out PDF forms, setting permissions, merging files, drawing vector graphics, tables, and text, use custom fonts, etc, etc.  If you are willing to work with it, you can get some pretty spectacular results. </p>\n\n<p>The one drawback is that it appears the developer has left this product out to pasture for a long time.  The developer site is still copyright 2003 and doesn\'t mention anything past ColdFusion MX 6.1.  I ended up having to break some of the encrypted templates in order to fix a couple of bugs and make it work as I needed it to.  Nontheless, it is a powerful tool.</p>\n'}]
['https://Stackoverflow.com/questions/73964', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2232/']