我有一个网页,用户可以在其中打印此页面或将其保存在他/她的计算机上。
如何将其保存为 Word 或 PDF 文档?
谢谢。
对于 MS Word 要求,大多数版本的 Office 都可以解释基本的 html/xml。因此,您可能会将旧的 cfcontent hack 视为 POI 的更简单替代方案。(Word 包不如电子表格包成熟。)
基本上你生成 html,但是使用 cfheader/cfcontent告诉浏览器内容实际上是一个 Word 文档。这显然不是真正的 MS Word 文件。但它比大多数选项更简单。
http://msdn.microsoft.com/en-us/library/aa155477.aspx
<cfheader name="Content-Disposition" value="attachment; filename=someFile.doc">
<cfcontent type="application/msword">
... your html code here ...
对于 microsoft office 文档,您可以使用Apache POI 项目。这意味着在您的冷融合代码中,您需要使用一些基本的 java 代码来调用 poi 方法。
但是,如果您选择 pdf 文档,事情就容易多了。您可以使用带有 PDF格式选项的cfdocument 标签
使用 POI 或 OpenOffice 界面(取决于您的版本),您可以创建 Word 文档。使用内置的 PDF 生成工具,您可以创建 PDF 文档。但是,您只能将其作为选项提供。
无法覆盖保存/打印菜单功能。无论您如何处理,我都会保存源文档而不是 .doc 或 .pdf。同样,您不能阻止我打印原始文档,而不是准备好的 PDF。
这是一种对我有用的方法: 使用 ColdFusion 创建 PDF 或 FlashPaper
However, just like printing, you will have to sacrifice some graphics, so this would be best used for exporting content (but as you did not specify, I'm just clarifying that this is possible but at a cost).
Hope that helps.
Use cfdocument to display as a PDF, then they can just click the disk image to save it to their computer. Or you can use the filename= attribute of cfdocument to assign a filename to it, and it will prompt them to save it instead of displaying in the browser.