我在Coldfusion 11中运行此代码。
<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>
问题是我已将div的边距和填充设置为0,但左右两侧仍有一些空格。
有没有办法以编程方式删除此空间,以便背景跨越页面的整个宽度?
更新(2017年8月7日)
我根据James Moberg的评论/建议更新了代码。但问题仍然存在。这是更新的代码
<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>
答案 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>