2013-03-05 79 views
0

我正在尝试将HTML表格导出为PDF文档的ColdFusion。该HTML表格从外部CSS文件派生其样式。问题在于,在导出时,表格格式不在PDF文档中导出。我需要将表格导出为在浏览器中呈现(以及其格式)。在ColdFusion中将HTML表格及其样式导出为PDF

以下是相同的代码。

Content.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> 

任何帮助,高度赞赏。

+0

请张贴您的代码。没有看到它,我们无法真正帮助。 – 2013-03-05 13:34:46

+0

不要将CSS样式内联?你尝试过吗? – ale 2013-03-05 13:42:36

+0

@AlEverett文档样式不需要内联''但是如果它们在文档的某个地方定义的话,它们会更好地工作。大多数情况下,我们在下面使用我的解决方案,它运行良好,您不必维护多个css副本。我想我已经看到了一些链接的css文件实际工作的文档,但大多数情况下我们只是在'style'标签内使用'cfinclude'。 – Travis 2013-03-05 14:15:46

回答

3

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

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

感谢Travis的建议。我已经上传了上面的代码。但这似乎并不奏效。我也试过 @import url(“styles/tableStyle.css”); 但还没有运气。 – 2013-03-05 15:17:13

+0

可能会阻止文档中的HTML呈现,尽管处于cfdocument块中。删除它,看看会发生什么。 – Travis 2013-03-05 16:35:10

+0

非常感谢特拉维斯!这有帮助。 – 2013-03-05 18:24:45