允许用户将网页导出为PDF以提高可读性的最好方法是什么? [英] What is the best way to allow someone to export a webpage to PDF for readability?

查看:165
本文介绍了允许用户将网页导出为PDF以提高可读性的最好方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在线文档,显示从数据库值和应用程序值动态构建的报表。向用户显示哪种类型的报告是基于用户具有的各种安全权限。因此,通常管理员可以看到完整的报告,但客户服务顾问将只看到同一份报告的一部分。它做到这一点很好。

I have an online document which shows a report built dynamically from database values and application values. What type of report it shows to the user is based on various security permissions that a user has. So generally a Manager can see a full report, but a Customer Service adviser will only see part of that same report. It does this just fine.

但现在看到的在线相同的报告也需要PDF版本。我已经开始构建一个新的.CFM模板,应该处理渲染同一个文档的PDF版本。它本质上是一个重复的在线版本,但基本的CSS格式和改变方式的文档是结构化的(例如没有jquery选项卡)。它仍然有条件逻辑。

But now the same report that is seen 'online' also needs a PDF version. I have started to build a new .CFM template which should handle rendering a PDF version of the same document. Its essentially a duplicate of the online version but with basic CSS formatting and change to way the document is structured (e.g. no jquery tabs). It still has the conditional logic in it.

但我现在来到一个阶段,我认为可能很难处理同一文档的两个文件。我的意思是,如果在在线版本的变化,那么PDF版本的代码也必须改变。

But I have now come to a stage where I think it may be difficult to handle two files for the same document. What I mean is that if something changes in the 'online' version, then code in the PDF version also has to change.

这是唯一的办法或有什么更好的方法来处理从网页导出到PDF?

Is this the only way to go about this or is there any better method of tackling exporting to PDF from a webpage? I just feel I'm doing it wrong.

推荐答案

cfdocument标签允许您动态创建PDF文件。您可以允许用户以各种方式选择他们的输出格式。

The cfdocument tag allows you to dynamically create PDF files. You can allow users to choose their output formats in a variety of ways.

我最常使用的是在用户输入搜索参数的表单上包含一个选择控件。我的选择一般是HTML或Excel,但它是相同的一般想法。当处理表单提交时,我最后做显示的东西。它将类似于:

The one I use most often is to include a select control on the form where the user enters their search parameters. My choices are generally HTML or Excel, but it's the same general idea. When processing the form submission, I do the display stuff last. It will resemble this:

<cfif form.showas is 'html'>
code for web page
<cfelse>
code for something else
<cfif>

由于您的选择是HTML或PDF,cfsavecontent标记可能派上用场。

Since your choices are HTML or PDF, the cfsavecontent tag might come in handy.

如果没有从表单访问您的页面,可以使用cfsavecontent生成一个具有所有输出的会话变量。然后,在您的网页上,提供链接或按钮或允许用户呈现为PDF的东西。您所做的就是将会话变量与cfdocument标记和Bob的您的叔叔组合。

If your page is not accessed from a form, you could use cfsavecontent to generate a session variable with all the output. Then, on your web page, offer a link or button or something that allows the user to render as PDF. All you do is combine the session variable with the cfdocument tag and Bob's your uncle.

这篇关于允许用户将网页导出为PDF以提高可读性的最好方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆