【问题标题】:Export HTML Table & its style to PDF in ColdFusion在 ColdFusion 中将 HTML 表格及其样式导出为 PDF
【发布时间】: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 文档样式不需要内联&lt;td style = "..."&gt;,但如果在文档中的某处定义它们,它们会更好地工作。大多数情况下,我们在下面使用我的解决方案,它运行良好,您不必维护 css 的多个副本。我想我已经看过几个文档,其中链接的 css 文件实际上可以工作,但大多数情况下我们只是在 style 标签内使用 cfinclude
  • 感谢艾尔埃弗雷特。我们在这里使用外部样式表。内联可能会有所帮助,但使用它可能会给代码维护带来更多负担。
  • 欢迎来到 ColdFusion 的 PDF 生成世界。 CSS 太可怕了。正如人们所提到的,尽可能多地使用标签上的样式属性来做内联 CSS。我还怀疑它也适用于'old skool' HTML(HTML 4)。尝试一个测试用例,就好像您正在为电子邮件发送者开发 HTML。来自一个不容错过的时代的旧的、看起来很可怕的代码。

标签: css html-table coldfusion pdf-generation


【解决方案1】:

显示您正在使用的代码将有助于我们回答这个问题,但是,您的 cfdocument 块中是否有您的 CSS 链接?如果您这样做了,但仍然无法正常工作,请尝试:

<cfdocument ...>
    <html> 
        <head>      
            <style>
                <cfinclude template = "yourCSSfile.css">
            </style>
        </head>
        <body>
            <table>
                ...
            </table>
        </body>
    </html>
</cfdocument>

【讨论】:

  • 感谢特拉维斯的建议。我已经上传了上面的代码。但这似乎不起作用。我也试过 @import url("styles/tableStyle.css");但还没有运气。
  • 可能会阻止文档中的 HTML 呈现,尽管它位于 cfdocument 块中。删除它,看看会发生什么。
猜你喜欢
  • 2011-09-21
  • 2018-06-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-26
  • 1970-01-01
相关资源
最近更新 更多