2017-08-05 26 views
0

我有這樣的代碼ColdFusion的運行11CFDOCUMENT插入上留有一定餘量和權利,即使設置爲0

<cfset fileName = "test.pdf"> 
<cfcontent type="application/pdf" reset="true"> 
<cfheader name="Content-Disposition" value="attachment; filename=#fileName#"> 
<cfdocument localurl="yes" format="pdf" pagetype="letter" margintop=".5" marginbottom=".5" marginright="0" marginleft="0" orientation="portrait" unit="in" backgroundvisible="yes" overwrite="yes" fontembed="no"> 
    <cfdocumentsection> 
     <div style="width:100%; background-color: #cccccc; margin: 0 0 0 0;padding: 0 0 0 0;"> 
      <h1>Hello World!</h1> 
     </div> 
    </cfdocumentsection> 
</cfdocument> 

這會產生這樣一個PDF: enter image description here

的問題是,我已將div的邊距和填充設置爲0,但左側和右側仍然有一些空間。

有沒有辦法以編程方式刪除此空間,以便背景跨越整個頁面寬度?

更新(2017年8月7日)

我已經更新了代碼,每從詹姆斯·莫伯格意見/建議。但問題仍然存在。以下是更新後的代碼

<cfset fileName = "test.pdf"> 
<cfcontent type="application/pdf" reset="true"> 
<cfheader name="Content-Disposition" value="attachment; filename=#fileName#"> 
<cfdocument localurl="yes" format="pdf" pagetype="letter" margintop=".5" marginbottom=".5" marginright="0" marginleft="0" orientation="portrait" unit="in" backgroundvisible="yes" overwrite="yes" fontembed="no"> 
    <?xml version="1.0" encoding="UTF-8"?> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
     <title>Test</title> 
     <meta http-equiv=Content-Type content="text/html; charset=windows-1252" /> 
     <meta name=Generator content="Microsoft Word 12 (filtered)" /> 
    </head> 
    <body style="margin: 0;padding: 0;"> 

    <cfdocumentsection> 
     <div style="width:100%; background-color: #cccccc; margin: 0;padding: 0;"> 
      <h1>Hello World!</h1> 
     </div> 
    </cfdocumentsection> 

    </body> 
    </html> 
</cfdocument> 
+1

您沒有BODY標籤。如果您使用瀏覽器查看該內容,則也會有填充/邊距。添加邊距/填充爲「0」的BODY,看看它是否有任何區別。 (如果你想要更好的字體/ CSS/SVG /邊框支持,請查看WKHTMLTOPDF。我使用它的方式是CF8-2016。) –

+0

Hello @JamesMoberg,謝謝你的建議。我嘗試使用body標籤,但問題仍然存在。我希望我已經與cfdocumentsection一起正確使用它。我正在編輯一些使用cfdocument實現的舊代碼。也許從長遠來看,我可以考慮使用WKHTMLTOPDF,但現在我急於實現對當前功能的一些更改。 –

+0

你在身體標記中使用CSS嗎? CFDocument HTML解析器已過時。您可能需要使用leftmargin =「0」topmargin =「0」rightmargin =「0」bottommargin =「0」marginwidth =「0」marginheight =「0」 –

回答

0

試試這個,我已經能夠創建使用CSS相對和絕對位置使用ColdFusion全定製PDF格。將您的cfdocumentsection替換爲以下內容。

<cfdocumentsection> 
    <div style="position:relative;left:-0.06in;width:102%;"> 
    <div style="background-color:#cccccc;"> 
     <h1>Hello World!</h1> 
    </div> 
    <div style="background-color:red;"> 
     <h1>Hello World!</h1> 
    </div> 
    </div> 
</cfdocumentsection> 
相關問題