2013-03-05 126 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