ColdFusion - converting HTML webpage to Word or PDF document

扶醉桌前 提交于 2019-12-23 05:47:06

问题


I have a webpage, where user has a possible to Print this page OR to save it on his/her computer.

How may I save it as a Word or PDF document?

Thanks.


回答1:


For the MS Word requirement, most versions of Office can interpret basic html/xml. So you might consider the old cfcontent hack as a simpler alternative to POI. (The Word package is not quite as mature as the spreadsheet package.)

Basically you generate html, but use cfheader/cfcontent to tell the browser the content is really a Word document. It is obviously not a true MS Word file. But it is simpler than most options.

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



回答2:


For microsoft office documents you can use the Apache POI project. This means in your coldfusion code you need to use some basic java code to call the poi methods.

However, if you choose the pdf document things are quite easier. You can use the cfdocument tag with the PDF format option




回答3:


Using the POI or OpenOffice interface (depending on your version) you can create a Word doc. Using the built-in PDF generation tools, you can create a PDF doc. HOwever, you can only present that as an option.

There is no way to override the save/print menu functions. No matter how you handle it, I cna save the source document instead of the .doc or .pdf. Similarly, you cannot prevent me from printing the original document, instead of a prepared PDF.




回答4:


Here is a method that has worked for me: Create PDF or FlashPaper with ColdFusion

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.




回答5:


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.



来源:https://stackoverflow.com/questions/3966584/coldfusion-converting-html-webpage-to-word-or-pdf-document

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!