【发布时间】:2013-03-05 11:38:19
【问题描述】:
我正在尝试将 HTML 表格导出为 PDF 文档的 ColdFusion。此 HTML 表格从外部 CSS 文件派生其样式。问题是导出时,表格格式未在 pdf 文档中导出。我需要将表格导出为在浏览器上呈现的内容(连同其格式)。
以下是相同的代码。
内容.cfm
<cfsavecontent variable="pdfREPORT">
<table id="dep" class="main_table" cellpadding="0">
<tr class="h1">
<th>cell1</th>
<th>cell2</th>
<th>cell3</th>
<th>cellN</th>
</tr>
.
.
.
<cfoutput query="qry1">
<tr>
<td>#qry1.col1#</td>
<td>#qry1.col2#</td>
<td>#qry1.col3#</td>
<td>#qry1.colN#</td>
</tr>
</cfoutput>
</table>
</cfsavecontent>
extract_to_pdf.cfm
<cfsetting enablecfoutputonly="true">
<cfheader name="Content-Disposition" value="inline;filename=test.pdf">
<cfcontent type="application/pdf">
<cfdocument format="PDF" localurl="yes" marginTop=".25" marginLeft=".25" marginRight=".25" marginBottom=".25"
pageType="custom" pageWidth="8.5" pageHeight="10.2" mimetype="text/html">
<html>
<head>
<style>
<cfinclude template = "styles/tableStyle.css">
</style>
</head>
<body>
<cfoutput>#Form.pdfREPORT#</cfoutput>
</body>
</html>
</cfdocument>
非常感谢任何帮助。
【问题讨论】:
-
请发布您的代码。如果没有看到它,我们真的无能为力。
-
CSS 样式不是必须内联吗?你试过吗?
-
@AlEverett 文档样式不需要内联
<td style = "...">,但如果在文档中的某处定义它们,它们会更好地工作。大多数情况下,我们在下面使用我的解决方案,它运行良好,您不必维护 css 的多个副本。我想我已经看过几个文档,其中链接的 css 文件实际上可以工作,但大多数情况下我们只是在style标签内使用cfinclude。 -
感谢艾尔埃弗雷特。我们在这里使用外部样式表。内联可能会有所帮助,但使用它可能会给代码维护带来更多负担。
-
欢迎来到 ColdFusion 的 PDF 生成世界。 CSS 太可怕了。正如人们所提到的,尽可能多地使用标签上的样式属性来做内联 CSS。我还怀疑它也适用于'old skool' HTML(HTML 4)。尝试一个测试用例,就好像您正在为电子邮件发送者开发 HTML。来自一个不容错过的时代的旧的、看起来很可怕的代码。
标签: css html-table coldfusion pdf-generation