How do I turn a ColdFusion page into a PDF download?

后端 未结 4 1036
说谎
说谎 2021-02-05 14:07

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.

4条回答
  •  心在旅途
    2021-02-05 14:59

    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.

    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.

    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.

提交回复
热议问题