从当前文档生成pdf [英] Generate pdf from current document

查看:231
本文介绍了从当前文档生成pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一种方法来从当前打开的coldfusion文档动态生成pdf。但我不知道如何处理这个,因为我没有找到一个方法ie,传递当前(html)文本到一个函数,通过使用cfdocument标签生成pdf。

I need a way to dynamicly generate a pdf from the currently opened coldfusion document. But I don't have an idea how to handle this because I didn't find a way i.e. to pass the current (html) text to a function which generates the pdf by using the cfdocument tag.

任何提示或想法,如何解决这个问题?

Any hints or ideas, how to solve this problem?

推荐答案

,您可以使用cfdocument的src属性通过内部自引用请求请求当前页面。Application.cfc中

Rather than capture the current response body, you could use the "src" attribute of cfdocument to request the current page via an internal self-referencing request.

<cffunction name="onRequestStart">

  <cfif IsDefined("url.showAsPDF") AND 
        url.showAsPDF IS "true" AND 
        cgi.http_user_agent IS NOT "ColdFusion">

    <cfset myURL = 
        "http" & 
         (IsDefined('CGI.HTTPS') AND CGI.HTTPS IS "On") ? "s" :  "") &
         "://#cgi.server_name#:#cgi.SERVER_PORT##cgi.script_name#?#cgi.query_string#">

    <cfdocument src="#myURL#" format="PDF"></cfdocument><cfabort>

  </cfif>
</cffunction>

这将查找名为showAsPDF的URL参数的存在。当定义并设置为true时,此代码将接管并在内部运行相同的请求,通过调用cfdocument进行路由。然后将响应作为PDF文档输出。

This will look for the presence of a URL parameter named "showAsPDF". When it is defined and set to "true", then this code will take over and run the same request internally, routed through a call to cfdocument. The response will then be output as a PDF document.

这篇关于从当前文档生成pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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