【问题标题】:CFDocument ImagesCF文档图像
【发布时间】:2013-05-14 19:33:49
【问题描述】:

我在 cfdocument 中显示图像时遇到问题。我尝试了几种不同的选项,但都没有运气(请参阅下面的测试代码)。

似乎cfdocument 认识到那里有一个图像文件,因为表格单元格的大小发生了变化。然而它仍然不显示图像的内容。 我将不胜感激。

    <cfdocument format="PDF" localURL = "yes">
    <p style="background-color:#006633">

    <table border="1">
    <tr><td><cfoutput>
            output from "file:///#ExpandPath('CEUCertificate_ABondy3.jpg')#" 
            </cfoutput>
        </td>
        <td style="background-color:white">
        <cfoutput>
           <image src="file:///#ExpandPath('CEUCertificate_ABondy3.jpg')#"> 
        </cfoutput>
        </td>
    </tr>
    <tr><td><cfoutput> output from #ExpandPath('CEUCertificate_ABondy3.jpg')#  </cfoutput> </td>
        <td>
        <cfoutput>
            <image src="#ExpandPath('CEUCertificate_ABondy3.jpg')#"> 
        </cfoutput>
        </td>
    </tr>
    <tr><td style="background-color:red">
            Output from: img src="CEUCertificate_ABondy3.jpg"
        </td>
        <td style="background-color:red"> 
            <img src="CEUCertificate_ABondy3.jpg"/>
        </td>
    </tr>
    <tr>
        <td style="background-color:white">
            output from image src="CEUCertificate_ABondy3.jpg"
        </td>
        <td>
            <cfoutput>
            <image src="CEUCertificate_ABondy3.jpg">
            </cfoutput>
    </tr>
    <tr>
        <td>Output from local url</td>
        <td>
             <cfoutput>
             <img src=#localUrl("CEUCertificate_ABondy3.jpg")#>
             </cfoutput>
        </td>
    </tr>
    </table>
    </p>
    </cfdocument>

    <cffunction name="localUrl" >
      <cfargument name="file" />

      <cfset var fpath = ExpandPath(file)>
      <cfset var f="">
      <cfset f = createObject("java", "java.io.File")>
      <cfset f.init(fpath)>

      <cfreturn f.toUrl().toString()>
    </cffunction>

【问题讨论】:

  • 如果你使用&lt;img src="/cde/mobileweb/CEUCertificate_ABondy3.jpg"/&gt;会发生什么?
  • 您为 CF 实例分配了多少内存?你试过增加它吗?
  • 亨利,我无法控制它。

标签: coldfusion cfdocument


【解决方案1】:

对于您的初始问题,您需要像处理任何其他 HTML 页面一样引用 cfdocument 标记中的图像; &lt;img src="url-to-the-image" /&gt;。所以这应该适合你。

<img src="/cde/mobileweb/CEUCertificate_ABondy3.jpg"/>

现在您已经进行了更改,页面正在超时。这可能是由于图像是如何创建的。 See this page here。我从Charlie's page here 找到的。

尝试在编辑器中打开该图像并重新保存。然后看看处理时间是否减少。

我在Ben Nadel's blog here 上找到了更多关于此的讨论。

【讨论】:

  • 谢谢!我已经尝试重新保存甚至调整大小,但我会用不同的编辑器再试一次。
  • 我无法让它工作。我使用 mpdf 库来创建 pdf。
  • 如果您找到了解决问题的其他方法,请将其作为问题的答案发布,以便其他人比这些 cmets 更容易找到它。很高兴你成功了。
【解决方案2】:

与其混淆ExpandPath()file://,不如将​​其编码为普通的html,并确保它首先工作。然后在你的&lt;cfdocument&gt;中使用localUrl="true"

【讨论】:

  • 我的代码中也使用了它。 没有显示。
  • @JanuszChudzynski 这是因为cfdocument 如何处理图像。您的代码正在 Web 根目录中查找图像,但它不存在。您是否尝试过我评论中的示例?
  • 是的。我收到以下错误:处理此文档的内容需要超过 60000 毫秒。
  • 这是进步的标志……至少 cfdocument 似乎在处理一些事情。
  • 您运行的代码是否超出了您与我们共享的代码?
猜你喜欢
  • 1970-01-01
  • 2011-12-03
  • 2013-04-17
  • 2022-06-15
  • 2020-06-28
  • 2012-04-13
  • 1970-01-01
  • 1970-01-01
  • 2019-08-02
相关资源
最近更新 更多