使用 ColdFusion 从 HTML 生成图像

发布于 2024-12-05 17:31:38 字数 143 浏览 0 评论 0原文

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

I have a ColdFusion page with a styled HTML table in it. What I would like to be able to do is set up a feature that allows our customers to save the table as an image file, for use in their slide shows. I have read some of the documentation for cfcontent however, I am beginning to get the feeling that I will need a third party library. I was hoping someone could shed some light on this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夢归不見 2024-12-12 17:31:38

您可以将 html 表渲染为静态页面,然后调用 http://code.google.com/ p/wkhtmltopdf/ 使用cfexecute渲染为pdf,或者wkhtmltoimage可以转换为.png .gif等

这是一个带有测试表和一些css表的静态页面。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>

制作一个简单的批处理文件wkhtmltoimage.bat

f:\temp\wkhtmltoimage --crop-h 250 --crop-w 200 http://localhost:8500/table.cfm f:\temp\outputfile.png 

更多命令行选项此处

使用 cfexecute运行批处理文件

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

输出非常好

输入图像此处说明

Windows 安装程序 libwkhtmltox-0.10.0_rc2.zip 包含 topdf 和 wkhtmltoimage

You could render your html table to a static page, then call http://code.google.com/p/wkhtmltopdf/ using cfexecute to render to pdf, or wkhtmltoimage can convert to .png .gif etc

Here's a static page with a test table and some 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>

Make a simple batch file wkhtmltoimage.bat

f:\temp\wkhtmltoimage --crop-h 250 --crop-w 200 http://localhost:8500/table.cfm f:\temp\outputfile.png 

More command line options here

Use cfexecute to run the batch file

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

Output is pretty nice

enter image description here

The windows installer libwkhtmltox-0.10.0_rc2.zip contains topdf and wkhtmltoimage

你的笑 2024-12-12 17:31:38

查看

check out <cfdocument format="PDF"> and <cfpdf action="thumbnail">

心头的小情儿 2024-12-12 17:31:38

可能不完全是你想要的,但 cfsilence 有一个来自 CF8 天的帖子可能有用:

初始帖子:
http:// /cfsilence.com/blog/client/index.cfm/2008/4/4/Converting-HTML-To-An-Image-With-CFJava

跟进:
http ://cfsilence.com/blog/client/index.cfm/2008/4/5/More-Thoughts-on-HTML-To-Image-Plus-Code

可能会帮助您开始......希望它有帮助!

Might not be exactly what you're after but cfsilence has a post from the CF8 days that might work:

Initial Post:
http://cfsilence.com/blog/client/index.cfm/2008/4/4/Converting-HTML-To-An-Image-With-CFJava

Follow Up:
http://cfsilence.com/blog/client/index.cfm/2008/4/5/More-Thoughts-on-HTML-To-Image-Plus-Code

Might get you started ... hope it's helpful!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文