使用ColdFusion从HTML生成图像

使用ColdFusion从HTML生成图像,coldfusion,jpeg,coldfusion-9,Coldfusion,Jpeg,Coldfusion 9,我有一个ColdFusion页面,其中有一个样式化的HTML表。我希望能够设置一个功能,允许我们的客户将表格保存为图像文件,以便在幻灯片放映中使用。我已经阅读了cfcontent的一些文档,但是我开始觉得我需要一个第三方库。我希望有人能解释一下 查看和可能并不完全是您想要的,但cfsilence有一篇来自CF8 days的帖子,可能有用: 初始职位: 后续行动: 可能会让你开始。。。希望对你有帮助 您可以将html表呈现为静态页面,然后使用cfexecute调用以呈现为pdf,或者wkhtm

我有一个ColdFusion页面,其中有一个样式化的HTML表。我希望能够设置一个功能,允许我们的客户将表格保存为图像文件,以便在幻灯片放映中使用。我已经阅读了cfcontent的一些文档,但是我开始觉得我需要一个第三方库。我希望有人能解释一下

查看

可能并不完全是您想要的,但cfsilence有一篇来自CF8 days的帖子,可能有用:

初始职位:

后续行动:


可能会让你开始。。。希望对你有帮助

您可以将html表呈现为静态页面,然后使用cfexecute调用以呈现为pdf,或者wkhtmltoimage可以转换为.png.gif等

这是一个静态页面,其中包含一个测试表和一些css table.cfm

<html>
<head>
    <title>Table test</title>

</head>
<style>
 *{
     margin:0;
     padding:0;
 }
 body{
     font-family: Georgia, serif;
     font-size: 20px;
     font-style: italic;
     font-weight: normal;
     letter-spacing: normal;
 }
 #content{
     padding:40px;
     margin:0 auto;
     -moz-box-shadow:0px 0px 16px #aaa;
 }

/* Table 1 Style */
table.table1{
    font-family: "Trebuchet MS", sans-serif;
    font-size: 16px;
    font-weight: bold;
    line-height: 1.4em;
    font-style: normal;
    border-collapse:separate;
}
.table1 thead th{
    padding:15px;
    color:#fff;
    text-shadow:1px 1px 1px #568F23;
    border:1px solid #93CE37;
    border-bottom:3px solid #9ED929;
    background-color:#9DD929;
    background:-webkit-gradient(
        linear,
        left bottom,
        left top,
        color-stop(0.02, rgb(123,192,67)),
        color-stop(0.51, rgb(139,198,66)),
        color-stop(0.87, rgb(158,217,41))
        );
    background: -moz-linear-gradient(
        center bottom,
        rgb(123,192,67) 2%,
        rgb(139,198,66) 51%,
        rgb(158,217,41) 87%
        );
    -webkit-border-top-left-radius:5px;
    -webkit-border-top-right-radius:5px;
    -moz-border-radius:5px 5px 0px 0px;
    border-top-left-radius:5px;
    border-top-right-radius:5px;
}
.table1 thead th:empty{
    background:transparent;
    border:none;
}
.table1 tbody th{
    color:#fff;
    text-shadow:1px 1px 1px #568F23;
    background-color:#9DD929;
    border:1px solid #93CE37;
    border-right:3px solid #9ED929;
    padding:0px 10px;
    background:-webkit-gradient(
        linear,
        left bottom,
        right top,
        color-stop(0.02, rgb(158,217,41)),
        color-stop(0.51, rgb(139,198,66)),
        color-stop(0.87, rgb(123,192,67))
        );
    background: -moz-linear-gradient(
        left bottom,
        rgb(158,217,41) 2%,
        rgb(139,198,66) 51%,
        rgb(123,192,67) 87%
        );
    -moz-border-radius:5px 0px 0px 5px;
    -webkit-border-top-left-radius:5px;
    -webkit-border-bottom-left-radius:5px;
    border-top-left-radius:5px;
    border-bottom-left-radius:5px;
}
.table1 tfoot td{
    color: #9CD009;
    font-size:32px;
    text-align:center;
    padding:10px 0px;
    text-shadow:1px 1px 1px #444;
}
.table1 tfoot th{
    color:#666;
}
.table1 tbody td{
    padding:10px;
    text-align:center;
    background-color:#DEF3CA;
    border: 2px solid #E7EFE0;
    -moz-border-radius:2px;
    -webkit-border-radius:2px;
    border-radius:2px;
    color:#666;
    text-shadow:1px 1px 1px #fff;
}
    </style>
<body>
<div id="content">

<table  class="table1">
<thead>
<tr>
    <th>column 1</th>
    <th>column 2</th>
    <th>column 3</th>
</tr>
</thead>
<tbody>
<tr>
    <td>1</td>
    <td>2</td>
    <td>3</td>
</tr>

<tr>
    <td>oranges</td>
    <td>lemons</td>
    <td>apples</td>
</tr>
</tbody>
<tfoot>
<tr>
    <td>red</td>
    <td>blue</td>
    <td>green</td>
</tr>

</tfoot>
</table>

</div>

</body>
</html>
更多命令行选项

使用cfexecute运行批处理文件

<cfexecute name="F:\temp\wkhtmltoimage.bat" timeout="20" variable="result"> 
</cfexecute> 

输出非常好


windows安装程序包含topdf和wkhtmltoimage

这应该可以让您非常接近所需内容,但简单的回答是CF没有将HTML转换为图像的功能。如果表格很小,那么我相信亨利在这里概述的方法会产生一个你不太感兴趣的缩略图——它会在表格周围显示很多空白(表格太小)。。。虽然值得一试。嗯,这就是我害怕的。有没有任何人知道的第三方支持?我在ColdFusion的第三方二维码支持上看到了一些东西,我想知道我正在尝试做的事情是否也有类似的东西?我希望我能帮上忙,但我有一个相同的问题:嗯,我希望我能早点找到你的帖子=|,无论如何,我会告诉你我发现了什么。至少是有见地的。也许对java程序员来说比我有用。IMGKit在Windows下工作?这是命令行还是ruby库?只是想知道为什么要使用外部程序而不是CF原生的CFDOCUMENT&CFPDF?我不是说你不应该只是想知道这是一个更好的解决方案,亨利早些时候的建议?好的问题是图像输出,而不是pdf和更多的控制图像分辨率裁剪大小等网页渲染引擎是WebKit,所以服务CSS样式的表应该是相当忠实的
<cfexecute name="F:\temp\wkhtmltoimage.bat" timeout="20" variable="result"> 
</cfexecute>